public interface SurveyBusiness extends IBOService {
	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurvey
	 */
	public SurveyEntity createSurvey(InformationFolder folder, String name,
			String description, IWTimestamp startTime, IWTimestamp endTime,
			String surveyTypePK) throws IDOLookupException, CreateException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurveyQuestion
	 */
	public SurveyQuestion createSurveyQuestion(SurveyEntity survey,
			String[] question, ICLocale[] locale, char answerType)
			throws IDOLookupException, CreateException,
			IDOAddRelationshipException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurveyQuestion
	 */
	public SurveyQuestion createSurveyQuestion(SurveyEntity survey,
			String question, ICLocale locale, char answerType)
			throws IDOLookupException, IDOAddRelationshipException,
			CreateException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurveyAnswer
	 */
	public SurveyAnswer createSurveyAnswer(SurveyQuestion question,
			String[] answer, ICLocale[] locale) throws IDOLookupException,
			CreateException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurveyAnswer
	 */
	public SurveyAnswer createSurveyAnswer(SurveyQuestion question,
			String answer, ICLocale locale) throws IDOLookupException,
			CreateException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurveyParticipant
	 */
	public SurveyParticipant createSurveyParticipant(String participantKey,
			SurveyEntity survey, User user, boolean alwaysCreateNew)
			throws IDOLookupException, CreateException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#removeSurveyRepliesForParticipant
	 */
	public void removeSurveyRepliesForParticipant(SurveyEntity survey,
			SurveyParticipant participant) throws RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#createSurveyReply
	 */
	public SurveyReply createSurveyReply(SurveyEntity survey,
			SurveyQuestion question, SurveyParticipant participant,
			SurveyAnswer answer, String answerText, IWTimestamp entryDate)
			throws IDOLookupException, CreateException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#updateSurveyQuestion
	 */
	public SurveyQuestion updateSurveyQuestion(SurveyEntity survey,
			SurveyQuestion question, String questionText, ICLocale locale,
			char type) throws IDOLookupException, CreateException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#updateSurveyAnswer
	 */
	public SurveyAnswer updateSurveyAnswer(SurveyAnswer ans,
			String answerString, ICLocale locale) throws IDOLookupException,
			CreateException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#removeQuestionFromSurvey
	 */
	public void removeQuestionFromSurvey(SurveyEntity survey,
			SurveyQuestion question, User user)
			throws IDORemoveRelationshipException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#removeAnswer
	 */
	public void removeAnswer(SurveyAnswer ans, User user)
			throws IDORemoveRelationshipException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getAnswerHome
	 */
	public SurveyAnswerHome getAnswerHome() throws IDOLookupException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyHome
	 */
	public SurveyEntityHome getSurveyHome() throws IDOLookupException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyTypeHome
	 */
	public SurveyTypeHome getSurveyTypeHome() throws IDOLookupException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getQuestionHome
	 */
	public SurveyQuestionHome getQuestionHome() throws IDOLookupException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyReplyHome
	 */
	public SurveyReplyHome getSurveyReplyHome() throws IDOLookupException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyParticipantHome
	 */
	public SurveyParticipantHome getSurveyParticipantHome()
			throws IDOLookupException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyStatusHome
	 */
	public SurveyStatusHome getSurveyStatusHome() throws IDOLookupException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#reportParticipation
	 */
	public SurveyParticipant reportParticipation(SurveyEntity survey,
			String participant) throws IDOLookupException, CreateException,
			RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyStatus
	 */
	public SurveyStatus getSurveyStatus(SurveyEntity survey)
			throws RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyType
	 */
	public SurveyType getSurveyType(SurveyEntity survey)
			throws FinderException, RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyTypeDropdownMenu
	 */
	public DropdownMenu getSurveyTypeDropdownMenu(IWResourceBundle iwrb,
			String name) throws RemoteException;

	/**
	 * @see com.idega.block.survey.business.SurveyBusinessBean#getSurveyTypes
	 */
	public Collection getSurveyTypes() throws RemoteException;
} public class SurveyBusinessBean extends IBOServiceBean implements
		SurveyBusiness {

	public final static char ANSWERTYPE_SINGLE_CHOICE = 's';
	public final static char ANSWERTYPE_MULTI_CHOICE = 'm';
	public final static char ANSWERTYPE_TEXTAREA = 't';

	/**
	 * 
	 */
	public SurveyBusinessBean() {
		super();
	}

	public SurveyEntity createSurvey(InformationFolder folder, String name,
			String description, IWTimestamp startTime, IWTimestamp endTime,
			String surveyTypePK) throws IDOLookupException, CreateException {
		SurveyEntity survey = getSurveyHome().create();

		survey.setFolder(folder.getEntity());

		survey.setName(name);
		if (description != null) {
			survey.setDescription(description);
		}

		if (startTime != null) {
			survey.setStartTime(startTime.getTimestamp());
		}

		if (endTime != null) {
			survey.setEndTime(endTime.getTimestamp());
		}
		if (surveyTypePK != null) {
			try {
				survey.setSurveyType(getSurveyTypeHome().findByPrimaryKey(
						surveyTypePK));
			} catch (FinderException e) {
				e.printStackTrace();
			}
		}

		survey.store();

		return survey;
	}

	public SurveyQuestion createSurveyQuestion(SurveyEntity survey,
			String[] question, ICLocale[] locale, char answerType)
			throws IDOLookupException, CreateException,
			IDOAddRelationshipException {
		SurveyQuestion sQuestion = getQuestionHome().create();

		if (question != null && locale != null) {
			for (int i = 0; i < question.length && i < locale.length; i++) {
				sQuestion.setQuestion(question[i], locale[i]);
			}
		}

		sQuestion.setAnswerType(answerType);

		sQuestion.store();

		survey.addQuestion(sQuestion);

		return sQuestion;
	}

	public SurveyQuestion createSurveyQuestion(SurveyEntity survey,
			String question, ICLocale locale, char answerType)
			throws IDOLookupException, IDOAddRelationshipException,
			CreateException {
		String[] questions = { question };
		ICLocale[] locales = { locale };
		return createSurveyQuestion(survey, questions, locales, answerType);
	}

	public SurveyAnswer createSurveyAnswer(SurveyQuestion question,
			String[] answer, ICLocale[] locale) throws IDOLookupException,
			CreateException {
		SurveyAnswer sAnswer = getAnswerHome().create();

		if (answer != null && locale != null) {
			for (int i = 0; i < answer.length && i < locale.length; i++) {
				sAnswer.setAnswer((answer[i] == null) ? "" : answer[i],
						locale[i]);
			}
		}

		sAnswer.setSurveyQuestion(question);

		sAnswer.store();

		return sAnswer;
	}

	public SurveyAnswer createSurveyAnswer(SurveyQuestion question,
			String answer, ICLocale locale) throws IDOLookupException,
			CreateException {
		String[] answers = { (answer == null) ? "" : answer };
		ICLocale[] locales = { locale };
		return createSurveyAnswer(question, answers, locales);
	}

	public SurveyParticipant createSurveyParticipant(String participantKey,
			SurveyEntity survey, User user, boolean alwaysCreateNew)
			throws IDOLookupException, CreateException {
		SurveyParticipant participant;
		if (alwaysCreateNew) {
			participant = getSurveyParticipantHome().create();
			participant.setParticipantName(participantKey);
			participant.setSurvey(survey);
			participant.setUser(user);
			participant.setEntryDate(IWTimestamp.getTimestampRightNow());

			participant.store();
		} else {
			try {
				participant = getSurveyParticipantHome().findParticipant(
						survey, user);
			} catch (FinderException e) {
				participant = getSurveyParticipantHome().create();
				participant.setParticipantName(participantKey);
				participant.setSurvey(survey);
				participant.setUser(user);
				participant.setEntryDate(IWTimestamp.getTimestampRightNow());

				participant.store();
			}
		}

		return participant;
	}

	public void removeSurveyRepliesForParticipant(SurveyEntity survey,
			SurveyParticipant participant) {
		try {
			Collection col = getSurveyReplyHome().findBySurveyAndParticipant(
					survey, participant);
			if (col != null && !col.isEmpty()) {
				Iterator it = col.iterator();
				while (it.hasNext()) {
					SurveyReply reply = (SurveyReply) it.next();
					reply.remove();
				}
			}
		} catch (IDOLookupException e) {
			e.printStackTrace();
		} catch (FinderException e) {
		} catch (EJBException e) {
			e.printStackTrace();
		} catch (RemoveException e) {
			e.printStackTrace();
		}
	}

	public SurveyReply createSurveyReply(SurveyEntity survey,
			SurveyQuestion question, SurveyParticipant participant,
			SurveyAnswer answer, String answerText, IWTimestamp entryDate)
			throws IDOLookupException, CreateException {
		SurveyReply reply = getSurveyReplyHome().create();

		reply.setSurvey(survey);
		reply.setQuestion(question);
		reply.setParticipantKey(participant.getParticipantName());
		reply.setParticipant(participant);
		reply.setEntryDate(entryDate.getTimestamp());

		if (answer != null) {
			reply.setAnswer(answer);
		}

		if (answerText != null) {
			if (answerText.length() > SurveyConstants.SURVEY_ANSWER_MAX_LENGTH) {
				reply.setAnswer(answerText.substring(0,
						SurveyConstants.SURVEY_ANSWER_MAX_LENGTH));
				reply.store();
				createSurveyReply(
						survey,
						question,
						participant,
						answer,
						answerText
								.substring(SurveyConstants.SURVEY_ANSWER_MAX_LENGTH),
						entryDate);
			} else {
				reply.setAnswer(answerText);
			}
		}

		reply.store();

		return reply;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.idega.block.survey.business.SurveyBusiness#updateSurveyQuestion(com.idega.block.survey.data.SurveyEntity,
	 *      com.idega.block.survey.data.SurveyQuestion, java.lang.String,
	 *      com.idega.core.localisation.data.ICLocale, char)
	 */
	public SurveyQuestion updateSurveyQuestion(SurveyEntity survey,
			SurveyQuestion question, String questionText, ICLocale locale,
			char type) throws IDOLookupException, CreateException {
		// ??use surveyEntity to see if the question is related to more than
		// this one and then create new Question
		question.setQuestion(questionText, locale);
		question.setAnswerType(type);
		question.store();
		return question;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.idega.block.survey.business.SurveyBusiness#updateSurveyAnswer(com.idega.block.survey.data.SurveyAnswer,
	 *      java.lang.String, com.idega.core.localisation.data.ICLocale)
	 */
	public SurveyAnswer updateSurveyAnswer(SurveyAnswer ans,
			String answerString, ICLocale locale) throws IDOLookupException,
			CreateException {
		ans.setAnswer(answerString, locale);
		ans.store();
		return ans;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.idega.block.survey.business.SurveyBusiness#removeQuestionFromSurvey(com.idega.block.survey.data.SurveyEntity,
	 *      com.idega.block.survey.data.SurveyQuestion)
	 */
	public void removeQuestionFromSurvey(SurveyEntity survey,
			SurveyQuestion question, User user)
			throws IDORemoveRelationshipException {
		// Collection answers =
		// this.getAnswerHome().findQuestionsAnswer(question);
		// for (Iterator aIter = answers.iterator(); aIter.hasNext();) {
		// this.removeAnswerFromQuestion(question,(SurveyAnswer)aIter.next(),user);
		// }
		survey.removeQuestion(question);
		question.setRemoved(user);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.idega.block.survey.business.SurveyBusiness#removeAnswerFromQuestion(com.idega.block.survey.data.SurveyQuestion,
	 *      com.idega.block.survey.data.SurveyAnswer)
	 */
	public void removeAnswer(SurveyAnswer ans, User user)
			throws IDORemoveRelationshipException {
		ans.setRemoved(user);
	}

	/**
	 * @return
	 */
	public SurveyAnswerHome getAnswerHome() throws IDOLookupException {
		return (SurveyAnswerHome) IDOLookup.getHome(SurveyAnswer.class);
	}

	/**
	 * @return
	 */
	public SurveyEntityHome getSurveyHome() throws IDOLookupException {
		return (SurveyEntityHome) IDOLookup.getHome(SurveyEntity.class);
	}

	public SurveyTypeHome getSurveyTypeHome() throws IDOLookupException {
		return (SurveyTypeHome) IDOLookup.getHome(SurveyType.class);
	}

	/**
	 * @return
	 */
	public SurveyQuestionHome getQuestionHome() throws IDOLookupException {
		return (SurveyQuestionHome) IDOLookup.getHome(SurveyQuestion.class);
	}

	/**
	 * @return
	 */
	public SurveyReplyHome getSurveyReplyHome() throws IDOLookupException {
		return (SurveyReplyHome) IDOLookup.getHome(SurveyReply.class);
	}

	/**
	 * @return
	 */
	public SurveyParticipantHome getSurveyParticipantHome()
			throws IDOLookupException {
		return (SurveyParticipantHome) IDOLookup
				.getHome(SurveyParticipant.class);
	}

	public SurveyStatusHome getSurveyStatusHome() throws IDOLookupException {
		return (SurveyStatusHome) IDOLookup.getHome(SurveyStatus.class);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.idega.block.survey.business.SurveyBusiness#reportParticipation(com.idega.block.survey.data.SurveyEntity,
	 *      java.lang.String)
	 */
	public SurveyParticipant reportParticipation(SurveyEntity survey,
			String participant) throws IDOLookupException, CreateException {
		SurveyParticipant sp = getSurveyParticipantHome().create();
		sp.setSurvey(survey);
		sp.setParticipantName(participant);
		sp.store();
		return sp;
	}

	public SurveyStatus getSurveyStatus(SurveyEntity survey) {
		try {
			try {
				return getSurveyStatusHome().findBySurvey(survey);
			} catch (IDOLookupException e) {
				e.printStackTrace();
			}
		} catch (FinderException e) {
			try {
				SurveyStatus status = getSurveyStatusHome().create();
				status.setSurvey(survey);
				status.setIsModified(true);
				status.store();
				return status;
			} catch (CreateException e1) {
				e1.printStackTrace();
			} catch (IDOLookupException e2) {
				e2.printStackTrace();
			}
		}

		return null;
	}

	public static final String SURVEY_TYPE_QUESTIONNAIRE = "questionnaire";
	public static final String SURVEY_TYPE_EXAM = "exam";
	public static final String SURVEY_TYPE_TEST = "test";
	private static final String DEFAULT_SURVEY_TYPE = SURVEY_TYPE_QUESTIONNAIRE;

	public SurveyType getSurveyType(SurveyEntity survey) throws FinderException {
		if (survey != null) {
			SurveyType type = survey.getSurveyType();
			if (type == null) {
				try {
					SurveyTypeHome stHome = (SurveyTypeHome) IDOLookup
							.getHome(SurveyType.class);
					type = stHome.findByName(DEFAULT_SURVEY_TYPE);
					survey.setSurveyType(type);
					survey.store();
					log("Setting default Survey Type (" + DEFAULT_SURVEY_TYPE
							+ ") to the Survey " + survey.getName());
				} catch (IDOLookupException e) {
					logError("Could not find default survey type : "
							+ DEFAULT_SURVEY_TYPE);
				}
			}
			return type;
		}
		return null;
	}

	public DropdownMenu getSurveyTypeDropdownMenu(IWResourceBundle iwrb,
			String name) {
		DropdownMenu menu = new DropdownMenu(name);
		Collection types = getSurveyTypes();
		if (types != null) {
			Iterator iter = types.iterator();
			while (iter.hasNext()) {
				SurveyType t = (SurveyType) iter.next();
				menu.addMenuElement(t.getPrimaryKey().toString(),
						iwrb.getLocalizedString(t.getLocalizationKey(), t
								.getName()));
			}
		}
		return menu;
	}

	public Collection getSurveyTypes() {
		try {
			SurveyTypeHome stHome = (SurveyTypeHome) IDOLookup
					.getHome(SurveyType.class);
			return stHome.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

} public interface SurveyAnswer extends IDOEntity {
	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#getSurveyQuestion
	 */
	public SurveyQuestion getSurveyQuestion();

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setSurveyQuestion
	 */
	public void setSurveyQuestion(SurveyQuestion question);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#getAnswer
	 */
	public String getAnswer(ICLocale locale) throws IDOLookupException,
			FinderException;

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setAnswer
	 */
	public void setAnswer(String question, ICLocale locale)
			throws IDOLookupException, CreateException;

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#useTextInput
	 */
	public boolean useTextInput();

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setToUseTextInput
	 */
	public void setToUseTextInput(boolean value);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setToUseTextInput
	 */
	public void setToUseTextInput(Boolean value);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setCreationLocale
	 */
	public void setCreationLocale(ICLocale locale);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#getCreationLocale
	 */
	public ICLocale getCreationLocale();

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#getDisableDependantQuestions
	 */
	public boolean getDisableDependantQuestions();

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#getEnableCheckedDepenantQuestions
	 */
	public boolean getEnableCheckedDepenantQuestions();

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setDisableDepenantQuestions
	 */
	public void setDisableDepenantQuestions(boolean disable);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setEnableCheckedDepenantQuestions
	 */
	public void setEnableCheckedDepenantQuestions(boolean enable);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#store
	 */
	public void store();

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setRemoved
	 */
	public void setRemoved(User user);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#setCorrectAnswer
	 */
	public void setCorrectAnswer(boolean isCorrect);

	/**
	 * @see com.idega.block.survey.data.SurveyAnswerBMPBean#getIsCorrectAnswer
	 */
	public boolean getIsCorrectAnswer();
} public interface SurveyAnswerHome extends IDOHome {
	public SurveyAnswer create() throws CreateException;

	public SurveyAnswer findByPrimaryKey(Object pk) throws FinderException;

	public Collection findQuestionsAnswer(SurveyQuestion question)
			throws FinderException;
} public interface SurveyEntity extends IDOEntity {
	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getName
	 */
	public String getName();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getDescription
	 */
	public String getDescription();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setName
	 */
	public void setName(String name);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setDescription
	 */
	public void setDescription(String description);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getStartTime
	 */
	public Timestamp getStartTime();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getEndTime
	 */
	public Timestamp getEndTime();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setStartTime
	 */
	public void setStartTime(Timestamp time);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setEndTime
	 */
	public void setEndTime(Timestamp time);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getCanUserAnswerMoreThanOnce
	 */
	public boolean getCanUserAnswerMoreThanOnce();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setCanUserAnswerMoreThanOnce
	 */
	public void setCanUserAnswerMoreThanOnce(boolean canAnswerMultipleTimes);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#addQuestion
	 */
	public void addQuestion(SurveyQuestion question)
			throws IDOAddRelationshipException;

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#removeQuestion
	 */
	public void removeQuestion(SurveyQuestion question)
			throws IDORemoveRelationshipException;

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getFolderID
	 */
	public int getFolderID();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getCategoryID
	 */
	public int getCategoryID();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setFolder
	 */
	public void setFolder(ICInformationFolder folder);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setCategoryID
	 */
	public void setCategoryID(ICInformationCategory categoryID);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getSurveyQuestions
	 */
	public Collection getSurveyQuestions() throws IDORelationshipException;

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setCreationLocale
	 */
	public void setCreationLocale(ICLocale locale);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getCreationLocale
	 */
	public ICLocale getCreationLocale();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#store
	 */
	public void store();

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setRemoved
	 */
	public void setRemoved(User user);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#setSurveyType
	 */
	public void setSurveyType(SurveyType type);

	/**
	 * @see com.idega.block.survey.data.SurveyEntityBMPBean#getSurveyType
	 */
	public SurveyType getSurveyType();
} public interface SurveyParticipant extends IDOEntity {
	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#setParticipantName
	 */
	public void setParticipantName(String name);

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#setSurvey
	 */
	public void setSurvey(SurveyEntity survey);

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#setUser
	 */
	public void setUser(User user);

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#setEntryDate
	 */
	public void setEntryDate(Timestamp entryDate);

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#getParticipantName
	 */
	public String getParticipantName();

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#getSurvey
	 */
	public SurveyEntity getSurvey();

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#getUser
	 */
	public User getUser();

	/**
	 * @see com.idega.block.survey.data.SurveyParticipantBMPBean#getEntryDate
	 */
	public Timestamp getEntryDate();
} public interface SurveyQuestion extends IDOEntity {
	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#store
	 */
	public void store();

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#getAnswerType
	 */
	public char getAnswerType();

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#getCreationLocale
	 */
	public ICLocale getCreationLocale();

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#getQuestion
	 */
	public String getQuestion(ICLocale locale) throws IDOLookupException,
			FinderException;

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#getDependantOnQuestion
	 */
	public SurveyQuestion getDependantOnQuestion();

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#getHasDependantQuestions
	 */
	public boolean getHasDependantQuestions();

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#getQuestionDisplayNumber
	 */
	public String getQuestionDisplayNumber();

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setAnswerType
	 */
	public void setAnswerType(char value);

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setQuestion
	 */
	public void setQuestion(String question, ICLocale locale)
			throws IDOLookupException, CreateException;

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setCreationLocale
	 */
	public void setCreationLocale(ICLocale locale);

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setRemoved
	 */
	public void setRemoved(User user);

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setDependantOnQuestion
	 */
	public void setDependantOnQuestion(SurveyQuestion question);

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setHasDepandantQuestions
	 */
	public void setHasDepandantQuestions(boolean hasDependantQuestions);

	/**
	 * @see com.idega.block.survey.data.SurveyQuestionBMPBean#setQuestionDisplayNumber
	 */
	public void setQuestionDisplayNumber(String displayNumber);
} public interface SurveyReply extends IDOEntity {
	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setParticipantKey
	 */
	public void setParticipantKey(String key);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setAnswer
	 */
	public void setAnswer(String answer);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setAnswer
	 */
	public void setAnswer(SurveyAnswer answer);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setSurvey
	 */
	public void setSurvey(SurveyEntity survey);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setQuestion
	 */
	public void setQuestion(SurveyQuestion question);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setAnswerPK
	 */
	public void setAnswerPK(Object answer);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setSurveyPK
	 */
	public void setSurveyPK(Object survey);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setQuestionPK
	 */
	public void setQuestionPK(Object question);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setParticipant
	 */
	public void setParticipant(SurveyParticipant participant);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#setEntryDate
	 */
	public void setEntryDate(Timestamp entryDate);

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getParticipantKey
	 */
	public String getParticipantKey();

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getAnswer
	 */
	public String getAnswer();

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getSurveyAnswer
	 */
	public SurveyAnswer getSurveyAnswer();

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getSurvey
	 */
	public SurveyEntity getSurvey();

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getQuestion
	 */
	public SurveyQuestion getQuestion();

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getParticipant
	 */
	public SurveyParticipant getParticipant();

	/**
	 * @see com.idega.block.survey.data.SurveyReplyBMPBean#getEntryDate
	 */
	public Timestamp getEntryDate();
} public interface SurveyReplyHome extends IDOHome {
	public SurveyReply create() throws CreateException;

	public SurveyReply findByPrimaryKey(Object pk) throws FinderException;

	public Collection findByQuestion(SurveyQuestion question)
			throws FinderException;

	public Collection findBySurveyAndParticipant(SurveyEntity survey,
			SurveyParticipant participant) throws FinderException;

	public Collection findByQuestions(Collection questions)
			throws FinderException;

	public int getCountByQuestionAndAnswer(SurveyQuestion question,
			SurveyAnswer answer) throws IDOException;

	public int getCountByQuestion(SurveyQuestion question) throws IDOException;
} public interface SurveyStatus extends com.idega.data.IDOEntity
{
 public boolean getIsModified();
 public com.idega.core.file.data.ICFile getReportFile();
 public com.idega.block.survey.data.SurveyEntity getSurvey();
 public java.sql.Timestamp getTimeOfStatus();
 public void setIsModified(boolean p0);
 public void setReportFile(com.idega.core.file.data.ICFile p0);
 public void setSurvey(com.idega.block.survey.data.SurveyEntity p0);
 public void store();
}
import java.rmi.RemoteException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import com.idega.block.survey.business.SurveyBusiness;
import com.idega.block.survey.business.SurveyBusinessBean;
import com.idega.block.survey.data.SurveyAnswer;
import com.idega.block.survey.data.SurveyAnswerHome;
import com.idega.block.survey.data.SurveyEntity;
import com.idega.block.survey.data.SurveyParticipant;
import com.idega.block.survey.data.SurveyQuestion;
import com.idega.block.survey.data.SurveyReply;
import com.idega.block.survey.data.SurveyReplyHome;
import com.idega.block.survey.data.SurveyStatus;
import com.idega.business.IBOLookup;
import com.idega.core.file.data.ICFile;
import com.idega.core.localisation.business.ICLocaleBusiness;
import com.idega.core.localisation.data.ICLocale;
import com.idega.data.IDOException;
import com.idega.data.IDOLookup;
import com.idega.data.IDOLookupException;
import com.idega.idegaweb.IWResourceBundle;
import com.idega.presentation.Block;
import com.idega.presentation.IWContext;
import com.idega.presentation.PresentationObject;
import com.idega.presentation.PresentationObjectContainer;
import com.idega.presentation.Table;
import com.idega.presentation.text.Link;
import com.idega.presentation.text.Text;
import com.idega.presentation.ui.BackButton;
import com.idega.presentation.ui.FieldSet;
import com.idega.presentation.ui.Form;
import com.idega.presentation.ui.IntegerInput;
import com.idega.presentation.ui.Legend;
import com.idega.presentation.ui.Parameter;
import com.idega.presentation.ui.SubmitButton;
import com.idega.util.IWTimestamp;
import com.idega.util.PresentationUtil;
import com.idega.util.poi.POIUtility;
package com.idega.block.survey.presentation;




/**
 * Title: SurveyResult Description: Copyright: Copyright (c) 2004 Company: idega
 * Software
 * 
 * @author 2004 - idega team - <br>
 *         <a href="mailto:gimmi@idega.is">Grimur Jonsson</a><br>
 * @version 1.0
 */
public class SurveyResultEditor extends Block {

	final static String IW_BUNDLE_IDENTIFIER = "com.idega.block.survey";

	public static String PARAMETER_SURVEY_ID = SurveyEditor.PRM_SURVEY_ID;
	private static String PARAMETER_STATUS_ID = "prmStId";
	private static String PARAMETER_NEW_STATUS = "prmNSt";
	private static String PARAMETER_CREATE_EXCEL = "prmCEx";
	private SurveyBusiness sBusiness;