public class CourseConstants {

	public static final String CASE_CODE_KEY = "COURSEA";

	public static final String IW_BUNDLE_IDENTIFIER = "is.idega.idegaweb.egov.course";

	public static final String ADMINISTRATOR_ROLE_KEY = "afterSchoolCareAdministrator";
	public static final String SUPER_ADMINISTRATOR_ROLE_KEY = "superAfterSchoolCareAdministrator";
	public static final String COURSE_ACCOUNTING_ROLE_KEY = "courseAccounting";

	public static final int DAY_CARE_NONE = 0;
	public static final int DAY_CARE_PRE = 1;
	public static final int DAY_CARE_POST = 2;
	public static final int DAY_CARE_PRE_AND_POST = 3;

	public static final String PROPERTY_REGISTRATION_EMAIL = "egov.course.registration.email";
	public static final String PROPERTY_BCC_EMAIL = "egov.course.bcc.email";
	public static final String PROPERTY_REFUND_EMAIL = "egov.course.refund.email";
	public static final String PROPERTY_HIDDEN_SCHOOL_TYPE = "egov.course.hidden.type";
	public static final String PROPERTY_MERCHANT_PK = "egov.course.merchant.pk";
	public static final String PROPERTY_MERCHANT_TYPE = "egov.course.merchant.type";
	public static final String PROPERTY_INVALIDATE_INTERVAL = "egov.course.invalidate.interval";
	public static final String PROPERTY_USE_DWR = "egov.course.use.dwr";
	public static final String PROPERTY_USE_FIXED_PRICES = "egov.course.use.fixed.prices";
	public static final String PROPERTY_USE_BIRTHYEARS = "egov.course.use.birthyears";
	public static final String PROPERTY_ACCOUNTING_TYPE_PK = "egov.course.accounting.type";
	public static final String PROPERTY_SHOW_ID_IN_NAME = "egov.course.show.id.in.name";
	public static final String PROPERTY_SHOW_PROVIDER = "egov.course.show.provider";
	public static final String PROPERTY_INCEPTION_YEAR = "egov.course.inception.year";
	public static final String PROPERTY_SHOW_ALL_COURSES = "egov.course.show.all.courses";
	public static final String PROPERTY_SHOW_CERTIFICATES = "egov.course.show.certificates";
	public static final String PROPERTY_SHOW_NO_PAYMENT = "egov.course.show.no.payment";
	public static final String PROPERTY_BACK_MONTHS = "egov.course.back.months";
	public static final String PROPERTY_USE_WAITING_LIST = "egov.course.use.waiting.list";
	public static final String PROPERTY_USE_DIRECT_PAYMENT = "egov.course.use.direct.payment";
	public static final String PROPERTY_SEND_REMINDERS = "egov.course.send.reminders";
	public static final String PROPERTY_PUBLIC_HOLIDAYS = "egov.course.public.holidays";
	public static final String PROPERTY_MANUALLY_OPEN_COURSES = "egov.course.manually.open";
	public static final String PROPERTY_ACCEPT_URL = "egov.course.accept.url";
	public static final String PROPERTY_SHOW_CARE_OPTIONS = "egov.course.show.care.options";
	public static final String PROPERTY_SHOW_PROVIDER_INFORMATION = "egov.course.show.provider.info";
	public static final String PROPERTY_SHOW_PERSON_INFORMATION = "egov.course.show.person.info";

	public static final String PROPERTY_TIMEOUT_DAY_OF_WEEK = "egov.course.timeout.day";
	public static final String PROPERTY_TIMEOUT_HOUR = "egov.course.timeout.hour";

	public static final String APPLICATION_PROPERTY_COURSE_MAP = "egov.course.map";

	public static final String CARD_TYPE_EUROCARD = "eurocard";
	public static final String CARD_TYPE_VISA = "visa";

	public static final String PAYMENT_TYPE_CARD = "credit_card";
	public static final String PAYMENT_TYPE_GIRO = "giro";
	public static final String PAYMENT_TYPE_BANK_TRANSFER = "bank_transfer";

	public static final String PRODUCT_CODE_CARE = "CARE";
	public static final String PRODUCT_CODE_COURSE = "COURSE";

	public static final String DISCOUNT_SIBLING = "sibling";
	public static final String DISCOUNT_QUANTITY = "quantity";
	public static final String DISCOUNT_SPOUSE = "spouse";

	public static final String COURSE_PREFIX = "course_";
	
	public static final String DEFAULT_COURSE_CERTIFICATE_FEE = "defaultCourseCertificateFee";

	public static final String PROPERTY_TIMER_HOUR = "egov.course.timer.hour";
	public static final String PROPERTY_TIMER_DAYOFWEEK = "egov.course.timer.dayofweek";
	public static final String PROPERTY_TIMER_MINUTE = "egov.course.timer.minute";

} public class CourseChoiceComparator implements Comparator {

	public static final int NAME_SORT = 1;
	public static final int DATE_SORT = 2;
	public static final int ID_SORT = 3;

	private Locale locale;
	private int compareBy = NAME_SORT;
	private Collator collator;

	public CourseChoiceComparator(Locale locale, int compareBy) {
		this.locale = locale;
		this.compareBy = compareBy;
	}

	public int compare(Object arg0, Object arg1) {
		CourseChoice choice1 = (CourseChoice) arg0;
		CourseChoice choice2 = (CourseChoice) arg1;
		collator = Collator.getInstance(locale);

		int returner = 0;
		switch (this.compareBy) {
			case ID_SORT:
				returner = idSort(choice1, choice2);
				break;

			case NAME_SORT:
				returner = nameSort(choice1, choice2);
				break;

			case DATE_SORT:
				returner = dateSort(choice1, choice2);
				break;

			default:
				returner = idSort(choice1, choice2);
				break;
		}

		return returner;
	}

	private int idSort(CourseChoice choice1, CourseChoice choice2) {
		return ((Integer) choice1.getPrimaryKey()).intValue() - ((Integer) choice2.getPrimaryKey()).intValue();
	}

	private int nameSort(CourseChoice choice1, CourseChoice choice2) {
		User user1 = choice1.getUser();
		User user2 = choice2.getUser();
		return collator.compare(user1.getName(), user2.getName());
	}

	private int dateSort(CourseChoice choice1, CourseChoice choice2) {
		CourseApplication application1 = choice1.getApplication();
		CourseApplication application2 = choice2.getApplication();
		
		IWTimestamp start1 = new IWTimestamp(application1.getCreated());
		IWTimestamp start2 = new IWTimestamp(application2.getCreated());

		if (start1.isEarlierThan(start2)) {
			return -1;
		}
		else if (start2.isEarlierThan(start1)) {
			return 1;
		}
		return 0;
	}
} public class CourseParticipantsWriter extends DownloadWriter implements MediaWritable {

	private MemoryFileBuffer buffer = null;
	private CourseBusiness business;
	private CitizenBusiness userBusiness;
	private Locale locale;
	private IWResourceBundle iwrb;

	private String courseName;

	public static final String PARAMETER_WAITING_LIST = "prm_waiting_list";
	
	public CourseParticipantsWriter() {
	}

	private Collection getChoices(Course course, IWContext iwc, boolean waitingList) {
		if (iwc.isParameterSet(CourseBlock.PARAMETER_COURSE_PARTICIPANT_PK)) {
			User participant = null;
			try {
				participant = userBusiness.getUser(Integer.valueOf(iwc.getParameter(CourseBlock.PARAMETER_COURSE_PARTICIPANT_PK)).intValue());
			} catch(Exception e) {
				e.printStackTrace();
			}
			if (participant == null) {
				return new ArrayList();
			}
			
			CourseChoice choise = null;
			try {
				choise = business.getCourseChoiceHome().findByUserAndCourse(participant, course);
			} catch (RemoteException e) {
				e.printStackTrace();
			} catch (FinderException e) {
				e.printStackTrace();
			}
			if (choise == null) {
				return new ArrayList();
			}
			return Arrays.asList(new CourseChoice[] {choise});
		}
		try {
			return business.getCourseChoices(course, waitingList);
		} catch (RemoteException e) {
			e.printStackTrace();
			return new ArrayList();
		}
	}
	
	@Override
	public void init(HttpServletRequest req, IWContext iwc) {
		try {
			this.locale = iwc.getApplicationSettings().getApplicationLocale();
			this.business = getCourseBusiness(iwc);
			this.userBusiness = getUserBusiness(iwc);
			this.iwrb = iwc.getIWMainApplication().getBundle(CourseConstants.IW_BUNDLE_IDENTIFIER).getResourceBundle(this.locale);

			if (req.getParameter(CourseBlock.PARAMETER_COURSE_PK) != null) {
				Course course = business.getCourse(iwc.getParameter(CourseBlock.PARAMETER_COURSE_PK));
				courseName = course.getName();
				
				boolean waitingList = iwc.isParameterSet(PARAMETER_WAITING_LIST);

				Collection choices = getChoices(course, iwc, waitingList);

				if (iwc.hasRole(CourseConstants.COURSE_ACCOUNTING_ROLE_KEY)) {
					this.buffer = writeAccountingXLS(iwc, choices);
				}
				else {
					this.buffer = writeXLS(iwc, choices);
				}
				String fileName = "participants.xls";
				if (iwc.isParameterSet(CourseBlock.PARAMETER_COURSE_PARTICIPANT_PK)) {
					fileName = "participant.xls";
				}
				setAsDownload(iwc, fileName, this.buffer.length());
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public String getMimeType() {
		if (this.buffer != null) {
			return this.buffer.getMimeType();
		}
		return super.getMimeType();
	}

	@Override
	public void writeTo(OutputStream out) throws IOException {
		if (this.buffer != null) {
			MemoryInputStream mis = new MemoryInputStream(this.buffer);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			while (mis.available() > 0) {
				baos.write(mis.read());
			}
			baos.writeTo(out);
		}
		else {
			System.err.println("buffer is null");
		}
	}

	public MemoryFileBuffer writeXLS(IWContext iwc, Collection choices) throws Exception {
		MemoryFileBuffer buffer = new MemoryFileBuffer();
		MemoryOutputStream mos = new MemoryOutputStream(buffer);

		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet(StringHandler.shortenToLength(this.courseName, 30));
		sheet.setColumnWidth(0, (30 * 256));
		sheet.setColumnWidth(1, (14 * 256));
		sheet.setColumnWidth(2, (30 * 256));
		sheet.setColumnWidth(3, (14 * 256));
		sheet.setColumnWidth(4, (14 * 256));
		HSSFFont font = wb.createFont();
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		font.setFontHeightInPoints((short) 12);
		HSSFCellStyle style = wb.createCellStyle();
		style.setFont(font);

		HSSFFont bigFont = wb.createFont();
		bigFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		bigFont.setFontHeightInPoints((short) 13);
		HSSFCellStyle bigStyle = wb.createCellStyle();
		bigStyle.setFont(bigFont);

		int cellRow = 0;
		HSSFRow row = sheet.createRow(cellRow++);
		HSSFCell cell = row.createCell(0);
		cell.setCellValue(this.courseName);
		cell.setCellStyle(bigStyle);
		
		row = sheet.createRow(cellRow++);

		boolean showAll = iwc.getApplicationSettings().getBoolean(CourseConstants.PROPERTY_USE_BIRTHYEARS, true);
		if (showAll) {
			row = sheet.createRow(cellRow++);
			cell = row.createCell(0);
			cell.setCellValue(this.iwrb.getLocalizedString("participant", "Participant"));
			cell.setCellStyle(bigStyle);
			cell = row.createCell(13);
			cell.setCellValue(this.iwrb.getLocalizedString("custodians", "Custodians"));
			cell.setCellStyle(bigStyle);
			cell = row.createCell(43);
			cell.setCellValue(this.iwrb.getLocalizedString("relatives", "Relatives"));
			cell.setCellStyle(bigStyle);
		}
		
		int iCell = 0;
		row = sheet.createRow(cellRow++);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("name", "Name"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("personal_id", "Personal ID"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("address", "Address"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("postal_code", "Postal code"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("home_phone", "Home phone"));
		cell.setCellStyle(style);

		if (showAll) {
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("child_care.growth_deviation", "Growth deviation"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("child_care.allergies", "Allergies"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("child.other_information", "Other information"));
			cell.setCellStyle(style);
			
			/* XXX Picked up */
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("picked_up", "Picked up"));
			cell.setCellStyle(style);

			/* XXX Pre-care and post-care*/
			String cellValue = this.iwrb.getLocalizedString("pre_care", "Has pre care");
			cellValue = cellValue + CoreConstants.SLASH;
			cellValue = cellValue + this.iwrb.getLocalizedString("post_care", "Has post care");
			cell = row.createCell(iCell++);
			cell.setCellValue(cellValue);
			cell.setCellStyle(style);
	
			for (int a = 1; a <= 3; a++) {
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("relation", "Relation"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("name", "Name"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("personal_id", "Personal ID"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("address", "Address"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("zip_code", "Zip code"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("home_phone", "Home phone"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("work_phone", "Work phone"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("mobile_phone", "Mobile phone"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("email", "E-mail"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("marital_status", "Marital status"));
				cell.setCellStyle(style);
			}
		}
		else {
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("work_phone", "Work phone"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("mobile_phone", "Mobile phone"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("email", "E-mail"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("register_date", "Register date"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("application.payer_personal_id", "Payer personal ID"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("application.payer_name", "Payer name"));
			cell.setCellStyle(style);
			cell = row.createCell(iCell++);
			cell.setCellValue(this.iwrb.getLocalizedString("application.reference_number", "Reference number"));
			cell.setCellStyle(style);
		}
		
		if (showAll) {
			for (int a = 1; a <= 2; a++) {
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("relation", "Relation"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("name", "Name"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("home_phone", "Home phone"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("work_phone", "Work phone"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("mobile_phone", "Mobile phone"));
				cell.setCellStyle(style);
				cell = row.createCell(iCell++);
				cell.setCellValue(this.iwrb.getLocalizedString("email", "E-mail"));
				cell.setCellStyle(style);
			}
		}
		
		User user;
		User owner;
		Address address;
		PostalCode postalCode = null;
		Phone phone;
		CourseChoice choice;
		CourseApplication application;

		Iterator iter = choices.iterator();
		while (iter.hasNext()) {
			row = sheet.createRow(cellRow++);
			choice = (CourseChoice) iter.next();
			application = choice.getApplication();
			user = choice.getUser();
			owner = application.getOwner();
			Child child = this.userBusiness.getMemberFamilyLogic().getChild(user);
			address = this.userBusiness.getUsersMainAddress(user);
			if (address != null) {
				postalCode = address.getPostalCode();
			}
			phone = this.userBusiness.getChildHomePhone(user);

			Name name = new Name(user.getFirstName(), user.getMiddleName(), user.getLastName());
			row.createCell(0).setCellValue(name.getName(this.locale, true));
			row.createCell(1).setCellValue(PersonalIDFormatter.format(user.getPersonalID(), this.locale));
			if (address != null) {
				row.createCell(2).setCellValue(address.getStreetAddress());
				if (postalCode != null) {
					row.createCell(3).setCellValue(postalCode.getPostalAddress());
				}
			}
			if (phone != null) {
				row.createCell(4).setCellValue(phone.getNumber());
			}

			if (showAll) {
				Boolean hasGrowthDeviation = child.hasGrowthDeviation(CourseConstants.COURSE_PREFIX + owner.getPrimaryKey());
				if (hasGrowthDeviation == null) {
					hasGrowthDeviation = child.hasGrowthDeviation(CourseConstants.COURSE_PREFIX);
				}
				if (hasGrowthDeviation != null && hasGrowthDeviation.booleanValue()) {
					row.createCell(5).setCellValue(this.iwrb.getLocalizedString("yes", "Yes"));
				}
				else {
					row.createCell(5).setCellValue(this.iwrb.getLocalizedString("no", "No"));
				}
	
				Boolean hasAllergies = child.hasAllergies(CourseConstants.COURSE_PREFIX + owner.getPrimaryKey());
				if (hasAllergies == null) {
					hasAllergies = child.hasAllergies(CourseConstants.COURSE_PREFIX);
				}
				if (hasAllergies != null && hasAllergies.booleanValue()) {
					row.createCell(6).setCellValue(this.iwrb.getLocalizedString("yes", "Yes"));
				}
				else {
					row.createCell(6).setCellValue(this.iwrb.getLocalizedString("no", "No"));
				}
	
				if (child.getOtherInformation(CourseConstants.COURSE_PREFIX + owner.getPrimaryKey()) != null) {
					row.createCell(7).setCellValue(child.getOtherInformation(CourseConstants.COURSE_PREFIX + owner.getPrimaryKey()));
				}
				else if (child.getOtherInformation(CourseConstants.COURSE_PREFIX) != null) {
					row.createCell(7).setCellValue(child.getOtherInformation(CourseConstants.COURSE_PREFIX));
				}

				/* Picked up */
				if (choice.isPickedUp()) {
					row.createCell(8).setCellValue(this.iwrb.getLocalizedString("yes", "Yes"));
				} else {
					row.createCell(8).setCellValue(this.iwrb.getLocalizedString("no", "No"));
				}

				/* Pre-care and post-care*/
				int dayCare = choice.getDayCare();
				if (dayCare > 0) {
					row.createCell(9).setCellValue(this.iwrb.getLocalizedString("yes", "Yes"));
				} else {
					row.createCell(9).setCellValue(this.iwrb.getLocalizedString("no", "No"));
				}

				iCell = 10;
	
				Collection custodians = new ArrayList();
				try {
					custodians = child.getCustodians();
				} catch(Exception e) {}
				Custodian extraCustodian = child.getExtraCustodian();
				if (extraCustodian != null) {
					custodians.add(extraCustodian);
				}
	
				Iterator iterator = custodians.iterator();
				while (iterator.hasNext()) {
					Custodian element = (Custodian) iterator.next();
					address = this.userBusiness.getUsersMainAddress(element);
					Phone work = null;
					Phone mobile = null;
					Email email = null;
					String relation = this.iwrb.getLocalizedString("relation." + child.getRelation(element), "relation." + child.getRelation(element));
					String maritalStatus = this.iwrb.getLocalizedString("marital_status." + element.getMaritalStatus(), "marital_status." + element.getMaritalStatus());
	
					try {
						phone = this.userBusiness.getUsersHomePhone(element);
					}
					catch (NoPhoneFoundException npfe) {
						phone = null;
					}
	
					try {
						work = this.userBusiness.getUsersWorkPhone(element);
					}
					catch (NoPhoneFoundException npfe) {
						work = null;
					}
	
					try {
						mobile = this.userBusiness.getUsersMobilePhone(element);
					}
					catch (NoPhoneFoundException npfe) {
						mobile = null;
					}
	
					try {
						email = this.userBusiness.getUsersMainEmail(element);
					}
					catch (NoEmailFoundException nefe) {
						email = null;
					}
	
					name = new Name(element.getFirstName(), element.getMiddleName(), element.getLastName());
					row.createCell(iCell++).setCellValue(relation);
					row.createCell(iCell++).setCellValue(name.getName(this.locale, true));
					row.createCell(iCell++).setCellValue(PersonalIDFormatter.format(element.getPersonalID(), this.locale));
					if (address != null) {
						row.createCell(iCell++).setCellValue(address.getStreetAddress());
						if (postalCode != null) {
							row.createCell(iCell++).setCellValue(postalCode.getPostalAddress());
						}
						else {
							iCell++;
						}
					}
					else {
						iCell++;
					}
					if (phone != null) {
						row.createCell(iCell++).setCellValue(phone.getNumber());
					}
					else {
						iCell++;
					}
					if (work != null) {
						row.createCell(iCell++).setCellValue(work.getNumber());
					}
					else {
						iCell++;
					}
					if (mobile != null) {
						row.createCell(iCell++).setCellValue(mobile.getNumber());
					}
					else {
						iCell++;
					}
					if (email != null) {
						row.createCell(iCell++).setCellValue(email.getEmailAddress());
					}
					else {
						iCell++;
					}
					if (maritalStatus != null) {
						row.createCell(iCell++).setCellValue(maritalStatus);
					}
					else {
						iCell++;
					}
				}
	
				iCell = 40;
	
				List relatives = new ArrayList();
				Relative mainRelative = child.getMainRelative(CourseConstants.COURSE_PREFIX + owner.getPrimaryKey());
				if (mainRelative == null) {
					mainRelative = child.getMainRelative(CourseConstants.COURSE_PREFIX);
				}
				if (mainRelative != null) {
					relatives.add(mainRelative);
				}
				Collection otherRelatives = child.getRelatives(CourseConstants.COURSE_PREFIX + owner.getPrimaryKey());
				if (otherRelatives.isEmpty()) {
					otherRelatives = child.getRelatives(CourseConstants.COURSE_PREFIX);
				}
				relatives.addAll(otherRelatives);
				iterator = relatives.iterator();
				while (iterator.hasNext()) {
					Relative element = (Relative) iterator.next();
					String relation = this.iwrb.getLocalizedString("relation." + element.getRelation(), "relation." + element.getRelation());
	
					row.createCell(iCell++).setCellValue(relation);
					row.createCell(iCell++).setCellValue(element.getName());
					row.createCell(iCell++).setCellValue(element.getHomePhone());
					row.createCell(iCell++).setCellValue(element.getWorkPhone());
					row.createCell(iCell++).setCellValue(element.getMobilePhone());
					row.createCell(iCell++).setCellValue(element.getEmail());
				}
			}
			else {
				iCell = 5;
				Phone work = null;
				Phone mobile = null;
				Email email = null;
				
				String payerName = null;
				String payerPersonalID = null;
				if (application.getPayerPersonalID() != null) {
					payerPersonalID = PersonalIDFormatter.format(application.getPayerPersonalID(), locale);
					payerName = application.getPayerName();
				}
				else {
					User payer = application.getOwner();
					payerName = new Name(payer.getFirstName(), payer.getMiddleName(), payer.getLastName()).getName(locale);
					payerPersonalID = PersonalIDFormatter.format(payer.getPersonalID(), locale);
				}

				try {
					work = this.userBusiness.getUsersWorkPhone(child);
				}
				catch (NoPhoneFoundException npfe) {
					work = null;
				}

				try {
					mobile = this.userBusiness.getUsersMobilePhone(child);
				}
				catch (NoPhoneFoundException npfe) {
					mobile = null;
				}

				try {
					email = this.userBusiness.getUsersMainEmail(child);
				}
				catch (NoEmailFoundException nefe) {
					email = null;
				}

				if (work != null) {
					row.createCell(iCell++).setCellValue(work.getNumber());
				}
				else {
					iCell++;
				}
				if (mobile != null) {
					row.createCell(iCell++).setCellValue(mobile.getNumber());
				}
				else {
					iCell++;
				}
				if (email != null) {
					row.createCell(iCell++).setCellValue(email.getEmailAddress());
				}
				else {
					iCell++;
				}
				row.createCell(iCell++).setCellValue(new IWTimestamp(application.getCreated()).getLocaleDate(locale, IWTimestamp.SHORT));
				row.createCell(iCell++).setCellValue(payerPersonalID);
				row.createCell(iCell++).setCellValue(payerName);
				if (application.getReferenceNumber() != null) {
					row.createCell(iCell++).setCellValue(application.getReferenceNumber());
				}
				else {
					iCell++;
				}
			}
		}
		wb.write(mos);
		buffer.setMimeType(MimeTypeUtil.MIME_TYPE_EXCEL_2);
		return buffer;
	}

	public MemoryFileBuffer writeAccountingXLS(IWContext iwc, Collection choices) throws Exception {
		MemoryFileBuffer buffer = new MemoryFileBuffer();
		MemoryOutputStream mos = new MemoryOutputStream(buffer);

		HSSFWorkbook wb = new HSSFWorkbook();
		HSSFSheet sheet = wb.createSheet(StringHandler.shortenToLength(this.courseName, 30));
		sheet.setColumnWidth(0,  (30 * 256));
		sheet.setColumnWidth(1,  (14 * 256));
		sheet.setColumnWidth(2,  (30 * 256));
		sheet.setColumnWidth(3,  (14 * 256));
		sheet.setColumnWidth(4,  (14 * 256));
		sheet.setColumnWidth(4,  (10 * 256));
		HSSFFont font = wb.createFont();
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		font.setFontHeightInPoints((short) 12);
		HSSFCellStyle style = wb.createCellStyle();
		style.setFont(font);

		HSSFFont bigFont = wb.createFont();
		bigFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		bigFont.setFontHeightInPoints((short) 13);
		HSSFCellStyle bigStyle = wb.createCellStyle();
		bigStyle.setFont(bigFont);

		int cellRow = 0;
		HSSFRow row = sheet.createRow(cellRow++);
		HSSFCell cell = row.createCell(0);
		cell.setCellValue(this.courseName);
		cell.setCellStyle(bigStyle);
		
		row = sheet.createRow(cellRow++);

		int iCell = 0;
		row = sheet.createRow(cellRow++);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("name", "Name"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("personal_id", "Personal ID"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("address", "Address"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("postal_code", "Postal code"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("home_phone", "Home phone"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("price", "Price"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("payer_personal_id", "Payer personal ID"));
		cell.setCellStyle(style);
		cell = row.createCell(iCell++);
		cell.setCellValue(this.iwrb.getLocalizedString("payer_name", "Payer name"));
		cell.setCellStyle(style);

		User user;
		Address address;
		PostalCode postalCode = null;
		Phone phone;
		CourseChoice choice;
		CourseApplication application;

		Iterator iter = choices.iterator();
		while (iter.hasNext()) {
			row = sheet.createRow(cellRow++);
			choice = (CourseChoice) iter.next();
			application = choice.getApplication();
			user = choice.getUser();
			address = this.userBusiness.getUsersMainAddress(user);
			if (address != null) {
				postalCode = address.getPostalCode();
			}
			phone = this.userBusiness.getChildHomePhone(user);
			Course course = choice.getCourse();
			User owner = application.getOwner();
			if (application.getPayerPersonalID() != null) {
				User payer = getUserBusiness(iwc).getUser(application.getPayerPersonalID());
				if (payer != null) {
					owner = payer;
				}
			}

			application = choice.getApplication();
			float userPrice = 0;
			if (choice.isNoPayment()) {
				userPrice = 0;
			}
			else {
				Map applicationMap = getCourseBusiness(iwc).getApplicationMap(application, new Boolean(false));
				SortedSet prices = getCourseBusiness(iwc).calculatePrices(applicationMap);
				Map discounts = getCourseBusiness(iwc).getDiscounts(prices, applicationMap);
				CoursePrice price = course.getPrice();
				
				float coursePrice = (price != null ? price.getPrice() : course.getCoursePrice()) * (1 - ((PriceHolder) discounts.get(user)).getDiscount());			
				
				float carePrice = 0;
				if (choice.getDayCare() == CourseConstants.DAY_CARE_PRE) {
					carePrice = price.getPreCarePrice();
				}
				else if (choice.getDayCare() == CourseConstants.DAY_CARE_POST) {
					carePrice = price.getPostCarePrice();
				}
				else if (choice.getDayCare() == CourseConstants.DAY_CARE_PRE_AND_POST) {
					carePrice = price.getPreCarePrice() + price.getPostCarePrice();
				}
				carePrice = carePrice * (1 - ((PriceHolder) discounts.get(user)).getDiscount());
				
				userPrice = carePrice + coursePrice;
			}
			
			Name name = new Name(user.getFirstName(), user.getMiddleName(), user.getLastName());
			row.createCell(0).setCellValue(name.getName(this.locale, true));
			row.createCell(1).setCellValue(PersonalIDFormatter.format(user.getPersonalID(), this.locale));
			if (address != null) {
				row.createCell(2).setCellValue(address.getStreetAddress());
				if (postalCode != null) {
					row.createCell(3).setCellValue(postalCode.getPostalAddress());
				}
			}
			if (phone != null) {
				row.createCell(4).setCellValue(phone.getNumber());
			}
			row.createCell(5).setCellValue(userPrice);
			
			if (owner != null) {
				row.createCell(6).setCellValue(owner.getPersonalID());
				row.createCell(7).setCellValue(new Name(user.getFirstName(), user.getMiddleName(), user.getLastName()).getName(this.locale, true));
			}
		}
		wb.write(mos);
		buffer.setMimeType(MimeTypeUtil.MIME_TYPE_EXCEL_2);
		return buffer;
	}

	private CourseBusiness getCourseBusiness(IWApplicationContext iwc) throws RemoteException {
		return (CourseBusiness) IBOLookup.getServiceInstance(iwc, CourseBusiness.class);
	}

	private CitizenBusiness getUserBusiness(IWApplicationContext iwc) throws RemoteException {
		return (CitizenBusiness) IBOLookup.getServiceInstance(iwc, CitizenBusiness.class);
	}
} public interface Course extends IDOEntity {

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getName
	 */
	public String getName();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getUser
	 */
	public String getUser();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getDescription
	 */
	public String getDescription();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getProvider
	 */
	public School getProvider();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getCourseType
	 */
	public CourseType getCourseType();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getPrice
	 */
	public CoursePrice getPrice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getCoursePrice
	 */
	public float getCoursePrice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getCourseCost
	 */
	public float getCourseCost();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getAccountingKey
	 */
	public String getAccountingKey();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getStartDate
	 */
	public Timestamp getStartDate();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getEndDate
	 */
	public Timestamp getEndDate();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getRegistrationEnd
	 */
	public Timestamp getRegistrationEnd();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getBirthyearFrom
	 */
	public int getBirthyearFrom();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getBirthyearTo
	 */
	public int getBirthyearTo();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getMax
	 */
	public int getMax();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getFreePlaces
	 */
	public int getFreePlaces();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getFreePlaces
	 */
	public int getFreePlaces(boolean countOffers);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#getCourseNumber
	 */
	public int getCourseNumber();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#isOpenForRegistration
	 */
	public boolean isOpenForRegistration();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#hasPreCare
	 */
	public boolean hasPreCare();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#hasPostCare
	 */
	public boolean hasPostCare();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#hasPreAndPostCarehasPreAndPostCare
	 */
	public boolean hasPreAndPostCare();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setName
	 */
	public void setName(String name);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setUser
	 */
	public void setUser(String user);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setDescription
	 */
	public void setDescription(String description);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setProvider
	 */
	public void setProvider(School provider);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setCourseType
	 */
	public void setCourseType(CourseType courseType);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setPrice
	 */
	public void setPrice(CoursePrice price);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setCoursePrice
	 */
	public void setCoursePrice(float price);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setCourseCost
	 */
	public void setCourseCost(float cost);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setAccountingKey
	 */
	public void setAccountingKey(String key);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setStartDate
	 */
	public void setStartDate(Timestamp startDate);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setEndDate
	 */
	public void setEndDate(Timestamp endDate);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setRegistrationEnd
	 */
	public void setRegistrationEnd(Timestamp registrationEnd);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setBirthyearFrom
	 */
	public void setBirthyearFrom(int from);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setBirthyearTo
	 */
	public void setBirthyearTo(int to);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setMax
	 */
	public void setMax(int max);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setCourseNumber
	 */
	public void setCourseNumber(int number);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setOpenForRegistration
	 */
	public void setOpenForRegistration(boolean openForRegistration);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setHasPreCare
	 */
	public void setHasPreCare(boolean hasPreCare);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseBMPBean#setHasPostCare
	 */
	public void setHasPostCare(boolean hasPostCare);

	public void setRentableItems(Collection<? extends RentableItem> items) throws IDOAddRelationshipException;
	public Collection<? extends RentableItem> getRentableItems(Class<? extends RentableItem> itemClass);
	public void addRentableItem(RentableItem item) throws IDOAddRelationshipException;
	public void removeRentableItem(RentableItem item) throws IDORemoveRelationshipException;
	public void removeAllRentableItems(Class<? extends RentableItem> itemClass) throws IDORemoveRelationshipException;

	public void addPrice(CoursePrice price) throws IDOAddRelationshipException;
	public Collection<CoursePrice> getAllPrices();
	public void removePrice(CoursePrice price) throws IDORemoveRelationshipException;
	public void removeAllPrices() throws IDORemoveRelationshipException;

	public void addSeason(SchoolSeason season) throws IDOAddRelationshipException;
	public Collection<SchoolSeason> getSeasons();
	public void removeSeason(SchoolSeason season) throws IDORemoveRelationshipException;
	public void removeAllSeasons() throws IDORemoveRelationshipException;

} public interface CourseCertificate extends IDOEntity {

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setCertificateType
	 */
	public void setCertificateType(CourseCertificateType type);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setCertificateFile
	 */
	public void setCertificateFile(ICFile file);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getCertificateFile
	 */
	public ICFile getCertificateFile();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getCourseCertificateType
	 */
	public CourseCertificateType getCourseCertificateType();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setParticipant
	 */
	public void setParticipant(User participant);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getParticipant
	 */
	public User getParticipant();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setCompany
	 */
	public void setCompany(Company company);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getCompany
	 */
	public Company getCompany();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setCourse
	 */
	public void setCourse(Course course);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getCourse
	 */
	public Course getCourse();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setValidFrom
	 */
	public void setValidFrom(Timestamp validFrom);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getValidFrom
	 */
	public IWTimestamp getValidFrom();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setValidThru
	 */
	public void setValidThru(Timestamp validThru);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getValidThru
	 */
	public IWTimestamp getValidThru();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#setNumber
	 */
	public void setNumber(int number);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseCertificateBMPBean#getNumber
	 */
	public int getNumber();
} public interface CourseCertificateHome extends IDOHome {

	public CourseCertificate create() throws CreateException;

	public CourseCertificate findByPrimaryKey(Object pk) throws FinderException;
	
	public Collection findAllCertificatesByUser(User user) throws FinderException;
	
	public Collection findAllCertificatesByUserAndCourse(User user, Course course) throws FinderException;
	
	public CourseCertificate findByUserAndCourse(User user, Course course) throws FinderException;
	
	public Collection findCertificatesByUsersAndValidityAndType(List usersIds, boolean onlyValidCertificates, String certificateTypeId) throws FinderException;

	public CourseCertificate findHighestNumber() throws FinderException;
} public interface CourseChoice extends IDOEntity {
	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getApplication
	 */
	public CourseApplication getApplication();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getCourse
	 */
	public Course getCourse();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getUser
	 */
	public User getUser();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getDayCare
	 */
	public int getDayCare();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getPaymentTimestamp
	 */
	public Timestamp getPaymentTimestamp();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isPickedUp
	 */
	public boolean isPickedUp();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isValid
	 */
	public boolean isValid();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#hasDyslexia
	 */
	public boolean hasDyslexia();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isOnWaitingList
	 */
	public boolean isOnWaitingList();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isNoPayment
	 */
	public boolean isNoPayment();
	
	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#hasReceivedReminder
	 */
	public boolean hasReceivedReminder();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#hasCreateLogin
	 */
	public boolean hasCreateLogin();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setApplication
	 */
	public void setApplication(CourseApplication application);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setCourse
	 */
	public void setCourse(Course course);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setUser
	 */
	public void setUser(User user);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setPaymentTimestamp
	 */
	public void setPaymentTimestamp(Timestamp timestamp);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setDayCare
	 */
	public void setDayCare(int dayCare);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setPickedUp
	 */
	public void setPickedUp(boolean pickedUp);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setValid
	 */
	public void setValid(boolean valid);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setHasDyslexia
	 */
	public void setHasDyslexia(boolean dyslexia);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setWaitingList
	 */
	public void setWaitingList(boolean waitingList);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setNoPayment
	 */
	public void setNoPayment(boolean noPayment);
	
	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setReceivedReminder
	 */
	public void setReceivedReminder(boolean hasReceivedReminder);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setHasCreateLogin
	 */
	public void setHasCreateLogin(boolean createLogin);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setPassed
	 */
	public void setPassed(boolean passed);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#hasPassed
	 */
	public boolean hasPassed();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setCourseCertificateFee
	 */
	public void setCourseCertificateFee(float fee);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getCourseCertificateFee
	 */
	public float getCourseCertificateFee();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isCertificateOfProperty
	 */
	public boolean isCertificateOfProperty();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isCriminalRecord
	 */
	public boolean isCriminalRecord();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isDidNotShowUp
	 */
	public boolean isDidNotShowUp();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isNeedVerificationFromGovermentOffice
	 */
	public boolean isNeedVerificationFromGovermentOffice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isVerificationFromGovermentOffice
	 */
	public boolean isVerificationFromGovermentOffice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isVerificationOfPayment
	 */
	public boolean isVerificationOfPayment();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setCertificateOfProperty
	 */
	public void setCertificateOfProperty(boolean certificateOfProperty);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setCriminalRecord
	 */
	public void setCriminalRecord(boolean criminalRecord);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#isLimitedCertificate
	 */
	public boolean isLimitedCertificate();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setDidNotShowUp
	 */
	public void setDidNotShowUp(boolean didNotShowUp);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setNeedsVerificationFromGovermentOffice
	 */
	public void setNeedsVerificationFromGovermentOffice(
			boolean needsVerificationFromOffice);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setVerificationFromGovermentOffice
	 */
	public void setVerificationFromGovermentOffice(
			boolean verificationFromGovermentOffice);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setVerificationOfPayment
	 */
	public void setVerificationOfPayment(boolean verificationOfPayment);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setLimitedCertificate
	 */
	public void setLimitedCertificate(boolean limitedCertificate);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getBooleanValueFromColumn
	 */
	public boolean getBooleanValueFromColumn(String columnName);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setBooleanValueForColumn
	 */
	public void setBooleanValueForColumn(boolean value, String columnName);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getNotes
	 */
	public String getNotes();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#getUniqueID
	 */
	public String getUniqueID();
	
	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setNotes
	 */
	public void setNotes(String notes);
	
	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseChoiceBMPBean#setUniqueID
	 */
	public void setUniqueID(String uniqueID);
} public interface CoursePrice extends IDOEntity {

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getName
	 */
	public String getName();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getSchoolArea
	 */
	public SchoolArea getSchoolArea();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getCourseType
	 */
	public CourseType getCourseType();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getValidFrom
	 */
	public Timestamp getValidFrom();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getValidTo
	 */
	public Timestamp getValidTo();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getNumberOfDays
	 */
	public int getNumberOfDays();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getPrice
	 */
	public int getPrice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getPreCarePrice
	 */
	public int getPreCarePrice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#getPostCarePrice
	 */
	public int getPostCarePrice();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setName
	 */
	public void setName(String name);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setSchoolArea
	 */
	public void setSchoolArea(SchoolArea area);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setCourseType
	 */
	public void setCourseType(CourseType type);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setValidFrom
	 */
	public void setValidFrom(Timestamp stamp);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setValidTo
	 */
	public void setValidTo(Timestamp stamp);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setValid
	 */
	public void setValid(boolean valid);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setNumberOfDays
	 */
	public void setNumberOfDays(int noDays);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setPrice
	 */
	public void setPrice(int price);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setPreCarePrice
	 */
	public void setPreCarePrice(int price);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CoursePriceBMPBean#setPostCarePrice
	 */
	public void setPostCarePrice(int price);

	public SchoolType getSchoolType();
	public void setSchoolType(SchoolType schoolType);

	public SchoolSeason getSchoolSeason();
	public void setSchoolSeason(SchoolSeason season);
} public interface CourseType extends IDOEntity {

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getName
	 */
	public String getName();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getDescription
	 */
	public String getDescription();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getLocalizationKey
	 */
	public String getLocalizationKey();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getCourseCategory
	 */
	public CourseCategory getCourseCategory();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getAccountingKey
	 */
	public String getAccountingKey();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getAbbreviation
	 */
	public String getAbbreviation();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#getOrder
	 */
	public int getOrder();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#showAbbreviation
	 */
	public boolean showAbbreviation();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#isDisabled
	 */
	public boolean isDisabled();

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setName
	 */
	public void setName(String name);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setDescription
	 */
	public void setDescription(String description);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setLocalizationKey
	 */
	public void setLocalizationKey(String localizationKey);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setCourseCategory
	 */
	public void setCourseCategory(CourseCategory category);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setAccountingKey
	 */
	public void setAccountingKey(String key);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setAbbreviation
	 */
	public void setAbbreviation(String abbreviation);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setOrder
	 */
	public void setOrder(int order);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setShowAbbreviation
	 */
	public void setShowAbbreviation(boolean showAbbreviation);

	/**
	 * @see is.idega.idegaweb.egov.course.data.CourseTypeBMPBean#setDisabled
	 */
	public void setDisabled(boolean disabled);
} public class PriceHolder implements Comparable<PriceHolder> {

	private String name;
	private User user = null;
	private float price = 0;
	private float discount = 0;
	private float cost = 0;

	public PriceHolder() {
		super();
	}

	public PriceHolder(String name) {
		this();
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public float getCost() {
		return cost;
	}

	public void setCost(float cost) {
		this.cost = cost;
	}

	public float getDiscount() {
		return discount;
	}

	public void setDiscount(float discount) {
		this.discount = discount;
	}

	@Override
	public int compareTo(PriceHolder obj) {
		int compare = (int) -(obj.getPrice() - getPrice());
		if (compare == 0) {
			compare = ((Integer) obj.getUser().getPrimaryKey()).intValue() - ((Integer) getUser().getPrimaryKey()).intValue();
		}

		return compare;
	}

	@Override
	public boolean equals(Object obj) {
		PriceHolder holder = (PriceHolder) obj;
		return holder.getUser().equals(getUser()) && holder.getPrice() == getPrice();
	}

	@Override
	public String toString() {
		return getUser().getName() + " - " + getPrice();
	}
} public class CourseParticipantListRowData {
	
	private String columnName = null;
	
	private boolean disabled = false;
	private boolean show = true;
	private boolean forceToCheck = false;
	
	public String getColumnName() {
		return columnName;
	}
	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}
	public boolean isDisabled() {
		return disabled;
	}
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
	public boolean isShow() {
		return show;
	}
	public void setShow(boolean show) {
		this.show = show;
	}
	public boolean isForceToCheck() {
		return forceToCheck;
	}
	public void setForceToCheck(boolean forceToCheck) {
		this.forceToCheck = forceToCheck;
	}
	
}
import is.idega.idegaweb.egov.citizen.presentation.CitizenFinder;
import is.idega.idegaweb.egov.course.CourseConstants;
import is.idega.idegaweb.egov.course.business.CourseChoiceComparator;
import is.idega.idegaweb.egov.course.business.CourseParticipantsWriter;
import is.idega.idegaweb.egov.course.data.Course;
import is.idega.idegaweb.egov.course.data.CourseCertificate;
import is.idega.idegaweb.egov.course.data.CourseCertificateHome;
import is.idega.idegaweb.egov.course.data.CourseChoice;
import is.idega.idegaweb.egov.course.data.CoursePrice;
import is.idega.idegaweb.egov.course.data.CourseType;
import is.idega.idegaweb.egov.course.data.PriceHolder;
import is.idega.idegaweb.egov.course.presentation.bean.CourseParticipantListRowData;
import java.rmi.RemoteException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import com.ibm.icu.text.NumberFormat;
import com.idega.block.school.data.School;
import com.idega.block.school.data.SchoolType;
import com.idega.builder.bean.AdvancedProperty;
import com.idega.business.IBORuntimeException;
import com.idega.core.builder.data.ICPage;
import com.idega.core.contact.data.Phone;
import com.idega.core.file.data.ICFile;
import com.idega.core.location.data.Address;
import com.idega.core.location.data.PostalCode;
import com.idega.data.IDOLookup;
import com.idega.presentation.IWContext;
import com.idega.presentation.Layer;
import com.idega.presentation.Table2;
import com.idega.presentation.TableCell2;
import com.idega.presentation.TableRow;
import com.idega.presentation.TableRowGroup;
import com.idega.presentation.text.Abbreviation;
import com.idega.presentation.text.DownloadLink;
import com.idega.presentation.text.Link;
import com.idega.presentation.text.Text;
import com.idega.presentation.ui.CheckBox;
import com.idega.presentation.ui.DropdownMenu;
import com.idega.presentation.ui.Form;
import com.idega.presentation.ui.GenericButton;
import com.idega.presentation.ui.HiddenInput;
import com.idega.presentation.ui.Label;
import com.idega.presentation.ui.SubmitButton;
import com.idega.user.data.User;
import com.idega.util.CoreConstants;
import com.idega.util.IWTimestamp;
import com.idega.util.PersonalIDFormatter;
import com.idega.util.PresentationUtil;
import com.idega.util.text.Name;
/*
 * $Id$ Created on Mar 28, 2007
 * 
 * Copyright (C) 2007 Idega Software hf. All Rights Reserved.
 * 
 * This software is the proprietary information of Idega hf. Use is subject to license terms.
 */
package is.idega.idegaweb.egov.course.presentation;




public class CourseParticipantsList extends CourseBlock {

	private static final int ACTION_VIEW = 1;
	private static final int ACTION_STORE = 2;

	public static final String PARAMETER_SHOW_COURSE_PARTICIPANT_INFO = "prm_show_course_participant_info";

	protected SchoolType type = null;
	
	protected ICPage changeEmailResponsePage = null;

	protected static final String PARAMETER_USER_PK = "cf_user_pk";
	protected static final String PARAMETER_USER_UNIQUE_ID = "cf_user_unique_id";
	protected static final String PARAMETER_SORTING = "prm_sorting";
	protected static final String PARAMETER_COURSE_PARTICIPANT_PAYMENT = "cf_participant_payment_";

	@Override
	public void present(IWContext iwc) {
		try {
			parseAction(iwc);
			
			Form form = new Form();
			form.setID("courseList");
			form.setStyleClass("adminForm");
			form.setEventListener(this.getClass());
			form.addParameter(PARAMETER_ACTION, String.valueOf(ACTION_VIEW));

			form.add(getNavigation(iwc));
			if (iwc.isParameterSet(PARAMETER_COURSE_PK)) {
				form.add(getPrintouts(iwc));
			}
			form.add(getParticipants(iwc));

			Layer buttonLayer = new Layer();
			buttonLayer.setStyleClass("buttonLayer");
			form.add(buttonLayer);

			boolean showNoPayment = iwc.getApplicationSettings().getBoolean(CourseConstants.PROPERTY_SHOW_NO_PAYMENT, false);