<%
/******************************************************************************
 * Copyright (c) 2000-2004 e-Deal
 *
 * e-Deal S.A.
 * 55 rue Brillat Savarin
 * 75013 Paris
 * France
 *
 * T: +33 (0)1 53 80 80 30
 * F: +33 (0)1 73 01 69 77
 * http://www.e-deal.com
 * 
 * La diffusion de ce code source sous quelque forme que ce soit sans
 * l'autorisation de E-DEAL est interdite.
 *
 * Vous êtes autorisés à modifier ce code source uniquement pour votre usage
 * propre et sous réserve que les mentions de copyright demeurent intactes.
 *
 * Ce code est fourni en l'état. Aucune garantie d'aucune sorte, explicite ou
 * implicite n'est donnée. En aucun cas E-DEAL ne pourra être tenu pour
 * responsable des dommages pouvant résulter de l'utilisation de ce code
 * source.
 *
 *
 ******************************************************************************/
%><%@page session="true" import="com.edeal.frontline.*,java.util.*,java.text.*,java.lang.reflect.*"%>
<%@ page import="com.edeal.frontline.navigation.FlRequest" %>
<%@taglib uri="http://www.e-deal.com/taglib/fl" prefix="fl" %>
<jsp:useBean class="com.edeal.frontline.FormResponseBean" id="FormResponse" scope="request"/>
<%
	final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
	FlRequest flRequest = new FlRequest(request);
	FlContext context = flRequest.getContext();
	DataDictionary dico = context.getDataDictionary();
	String contextPath = (String) session.getAttribute("contextPath");
	String parentTarget = " target=\"_parent\" ";
	String blankTarget = " target=\"_blank\" ";


String id = Utils.getRequestParameter(context, request, "id");
String isVrp = Utils.getRequestParameter(context, request, "vrp");
%>
<html>
<head>
	<link rel="stylesheet" href="<fl:webapp/>/css/common_css.jsp" type="text/css">
	<link rel="stylesheet" href="<fl:webapp/>/css/master_css.jsp" type="text/css">
	<script type="text/javascript" language="javascript" src="<fl:webapp/>/js/presentField.js"></script>	
	<script type="text/javascript" language="javascript" src="<fl:webapp/>/js/ajax/sarissa.js"></script>
	<script type="text/javascript" language="javascript" src="<fl:webapp/>/js/ajax/ajax.js"></script>

</head>
<body>
<table><tr><td style="height: 10px;"></td></tr></table>
<div id="object_css" style="top:0px;left: 0px;height:100%;">
<fl:bigTabs objectTitle="<%= Utils.getMessage(session, \"L63F4\", false, true, \"Réponse au questionnaire\")  %>">
<%
String perID = null;
try {
	perID = FormResponse.getFrpPersonID();
} catch (FieldNotInitializedException fnie) {
}

String formID = null;
try {
	formID = FormResponse.getFrpFormID();
} catch (FieldNotInitializedException fnie) {
}

String[][] queryForm = {{"FrmID = " + Utils.formatToSQL(context, formID)}};
String[] fieldsForm = {"FrmLabel" , "FrmSeqNum" , "FrmBasicQuestion0" , "FrmBasicQuestion1" , "FrmBasicQuestion2", "FrmEventID"};
String formLabel = "???";
String formNumber = "???";
String formEventID = null;

Vector listForm = FormBean.listSummary(session , fieldsForm , queryForm);
if (listForm != null && listForm.size() > 0) {
	formEventID = (String) ((Hashtable) listForm.elementAt(0)).get("FrmEventID");
	formLabel = (String) ((Hashtable) listForm.elementAt(0)).get("FrmLabel");
	Integer formNumberI = (Integer) ((Hashtable) listForm.elementAt(0)).get("FrmSeqNum");
	if (formNumberI != null) {
		DecimalFormat df = FlLocale.getInstance(session).getDecimalFormat("0000");
		formNumber = df.format((long) (formNumberI.intValue()));
	}
}

String[][] queryPer = {{"PerID = " + Utils.formatToSQL(context, perID)}};
String[] fieldsPer = {"PerCivID:Val" , "PerName" , "PerFstName"};
String perCompleteName = "???";
Vector listPer = PersonBean.listSummary(session , fieldsPer , queryPer);
if (listPer != null && listPer.size() > 0) {
	String perCiv = (String) ((Hashtable) listPer.elementAt(0)).get("PerCivID:Val");
	String perName = (String) ((Hashtable) listPer.elementAt(0)).get("PerName");
	String perFstName = (String) ((Hashtable) listPer.elementAt(0)).get("PerFstName");
	perCompleteName = (perCiv != null ? perCiv : "") + " " + (perFstName != null ? perFstName : "") + " " + (perName != null ? perName : "");
}

%>
<div align="center" style="font-size: 12pt ; font-weight: bold"><%= formNumber %> - <%= formLabel %></div>
<div align="center" style="font-size: 10pt ; font-weight: bold"><a href="<fl:webapp/>/read_person.fl?id=<%= perID %>" target="_self" style="font-size: 10pt"><%= perCompleteName %><a></div>
<table border="0" width="100%" cellspacing="3" cellpadding="3">
<%
String basicQuestion0=null; 
if(!listForm.isEmpty())
	basicQuestion0 = (String) ((Hashtable) listForm.elementAt(0)).get("FrmBasicQuestion0");
if (basicQuestion0 != null) {
	boolean basicResp0 = false;
	try {
		basicResp0 = FormResponse.isFrpBasicResponse0();
	} catch (FieldNotInitializedException fnie) {
	}
%>
	<tr><td valign="top" class="transparent dataLabel">
		<%= basicQuestion0 %>
	</td>
	<td class="dataLabel">
		<%= basicResp0 ? Utils.getMessage(session, "L2005", "Oui") : Utils.getMessage(session, "L2006", "Non") %>
	</td></tr>
<%
}
String basicQuestion1 = null;
if (!listForm.isEmpty()) {
		basicQuestion1 = (String) ((Hashtable) listForm.elementAt(0)).get("FrmBasicQuestion1");
	}
if (basicQuestion1 != null) {
	boolean basicResp1 = false;
	try {
		basicResp1 = FormResponse.isFrpBasicResponse1();
	} catch (FieldNotInitializedException fnie) {
	}
%>
	<tr><td valign="top" class="transparent dataLabel">
		<%= basicQuestion1 %>
	</td>
	<td class="dataLabel">
		<%= basicResp1 ? Utils.getMessage(session, "L2005", "Oui") : Utils.getMessage(session, "L2006", "Non") %>
	</td></tr>
<%
}
String basicQuestion2 = null;
if(!listForm.isEmpty())
	basicQuestion2 = (String) ((Hashtable) listForm.elementAt(0)).get("FrmBasicQuestion2");
if (basicQuestion2 != null) {
	boolean basicResp2 = false;
	try {
		basicResp2 = FormResponse.isFrpBasicResponse2();
	} catch (FieldNotInitializedException fnie) {
	}
%>
	<tr><td valign="top" class="transparent dataLabel">
		<%= basicQuestion2 %>
	</td>
	<td class="dataLabel">
		<%= basicResp2 ? Utils.getMessage(session, "L2005", "Oui") : Utils.getMessage(session, "L2006", "Non") %>
	</td></tr>
<%
}

String[][] query = {{"LfqFormID = " + Utils.formatToSQL(context, formID)}};
String[] fields = {"LfqID" , "LfqFormQuestionID" , "LfqParagraph", "LfqPosition"};
String[] orderBy = {"LfqPosition"};

Vector lfqList = LinkFormQuestionBean.listSummary(session, fields, query, orderBy);
if (lfqList != null && lfqList.size() > 0) {
	for (int i=0 ; i < lfqList.size() ; i++) {
		Hashtable line = (Hashtable) lfqList.elementAt(i);
		String questionID = (String) line.get("LfqFormQuestionID");
		String paragraph = (String) line.get("LfqParagraph");
		Integer lfqPosI = (Integer) line.get("LfqPosition");
		String lfqID = (String) line.get("LfqID");
		int lfqPosition = 99;
		if (lfqPosI != null) {
			lfqPosition = lfqPosI.intValue();
		}
		String lfqPos = Integer.toString(lfqPosition);
		if (paragraph != null) {
%>
<tr><th colspan="2"><%= paragraph %></th></tr>
<%
		} else {
			FormQuestionBean curQuestion = null;
			try {
				curQuestion = new FormQuestionBean(questionID , session);
			} catch (AccessDeniedException ade) {
			} catch (FrontlineException fex) {
			}
			if (curQuestion != null) {
				String qLabel = null;
				try {
					qLabel = curQuestion.getFqtLabel();
				} catch (FieldNotInitializedException fnie) {
				}
				String qTypeID = null;
				try {
					qTypeID = curQuestion.getFqtType();
				} catch (FieldNotInitializedException fnie) {
				}
				String qRefTableID = null;
				String qType = "FRE";
				if ( qTypeID != null && qTypeID.equals(dico.getRefIdByCode("FqtType" , "REF")) ) {
					qType = "REF";
					try {
						qRefTableID = curQuestion.getFqtRefTable();
					} catch (FieldNotInitializedException fnie) {
					}
				}
				if ( qTypeID != null && qTypeID.equals(dico.getRefIdByCode("FqtType" , "LST")) ) {
					qType = "LST";
				}
				if ( qTypeID != null && qTypeID.equals(dico.getRefIdByCode("FqtType" , "INT")) ) {
					qType = "INT";
				}
%>
<tr>
	<td valign="top" class="transparent dataLabel">
		<input type="hidden" name="<%= lfqPos %>_LfqID" value="<%= lfqID %>">
		<%= qLabel == null ? "&nbsp;" : qLabel %>
	</td>
	<td class="dataLabel">
<%
				String[][] queryQrs = {{"QrsFrpID = " + Utils.formatToSQL(context, id), "QrsLfqID = " + Utils.formatToSQL(context, lfqID)}};
				String[] orderByQrs = {"QrsInstance"};
				Vector listQrs = QuestionResponseBean.list(session , queryQrs, orderByQrs);
				if (listQrs != null && listQrs.size() > 0) {
					for (int j = 0 ; j < listQrs.size() ; j++) {
						QuestionResponseBean curQrs = (QuestionResponseBean) listQrs.elementAt(j);
						if ("FRE".equals(qType)) { //- debut cas FRE
							String qrsText = null;
							try {
								qrsText = curQrs.getQrsText();
							} catch (FieldNotInitializedException fnie) {
							}
%>
		<%= qrsText != null ? qrsText : "&nbsp;" %><%= j < listQrs.size() - 1 ? "<br>" : "" %>
<%
						} //- fin cas FRE
						
						if ("INT".equals(qType)) { // debut cas INT
							String qrsText = null;
							try {
								qrsText = curQrs.getQrsText();
							} catch (FieldNotInitializedException fnie) {
							}
							int qrsInstance = 0;
							try {
								qrsInstance = curQrs.getQrsInstance();
							} catch (FieldNotInitializedException fnie) {
							}
%>
		<%if(qrsInstance == 0){ %>
			<fl:getMessage code="L621C" alt="De"/> &nbsp;<%= (qrsText != null) ? qrsText : "&nbsp;" %>
		<% }else if(qrsInstance == 1){ %>
			&nbsp;<fl:getMessage code="L8254" alt="À"/>&nbsp;<%= (qrsText != null) ? qrsText : "&nbsp;" %>
		<% } %>	
		
<%							
							
						} //fin cas INT
						
						if ("LST".equals(qType)) { //- debut cas LST
							int qrsPosition = -1;
							try {
								qrsPosition = curQrs.getQrsPosition();
							} catch (FieldNotInitializedException fnie) {
							}
							String lstAnswer = null;
							try {
								Method getter = Class.forName("com.edeal.frontline.FormQuestionBean").getMethod("getFqtLstAnswer" + qrsPosition , null);
								lstAnswer = (String) getter.invoke(curQuestion , null);
							} catch (Exception e) {
								logger.error("DBG: " + e.getClass().getName() + " : " + e.getMessage());
							}
							String qrsMoreText = null;
							try {
								qrsMoreText = curQrs.getQrsMoreText();
							} catch (FieldNotInitializedException fnie) {
							}
							if (lstAnswer != null) {
%>
		<%= lstAnswer %><%= qrsMoreText != null ? " (" + qrsMoreText + ")" : "" %><%= j < listQrs.size() - 1 ? "<br>" : "" %>
<%
							}
						} //- fin cas LST
						
						if ("REF".equals(qType)) { //- debut cas REF
							String qrsRefValID = null;
							try {
								qrsRefValID = curQrs.getQrsRefValID();
							} catch (FieldNotInitializedException fnie) {
							}
							String qrsMoreText = null;
							try {
								qrsMoreText = curQrs.getQrsMoreText();
							} catch (FieldNotInitializedException fnie) {
							}
							String refAnswer = null;
							try {
								refAnswer = (String) dico.getRefDisp(session, qRefTableID , "Te1" , qrsRefValID);
							} catch (Exception fe) {
							//http://u-project2.umanis.com/view.php?id=45341 : from FrontlineException to Exception
							}
							if (refAnswer != null) {
%>
		<%= refAnswer %><%= qrsMoreText != null ? " (" + qrsMoreText + ")" : "" %><%= j < listQrs.size() - 1 ? "<br>" : "" %>
<%
							}
						} //- fin cas REF
					}
				}
%>
	</td>
<%
			}
		}
	}
}
%>	
</table>
<form method="post" action="<%= flRequest.computeURL("/save_personevent_scr.fl?id=" + id) %>" target="_self">
	<input type="hidden" name="op" value="save">
	<input type="hidden" name="$$multivalSeparator" value=";">
 	<input type="hidden" name="$$presentFields">
	<input type="hidden" name="$$returnedHtmlHead" value="">
<%
String[][] queryPev = {{"PvtPersonID = " + Utils.formatToSQL(context, perID) , "PvtEventId = " + Utils.formatToSQL(context, formEventID)}};
String[] fieldsPev = {"PvtID"};
Vector listPvt = PersonEventBean.listSummary(context, fieldsPev , queryPev);
if ( listPvt != null && listPvt.size() > 0 ) {
	String pvtID = (String) ((Hashtable) listPvt.elementAt(0)).get("PvtID");
%>
	<input type="hidden" name="id" value="<%= pvtID %>">
<%
} else {
%>
	<input type="hidden" name="PvtPersonID" value="<%= perID %>">
	<input type="hidden" name="PvtEventID" value="<%= formEventID %>">
	<input type="hidden" name="PvtFrpID" value="<%= id %>">
<%
}
%>
	<input type="hidden" name="PvtParStatus" value="5">
</form>
</fl:bigTabs>

<br>
	<div align="center" style="width: 100%">
		<input id="cancelbutton" type="image" src="<fl:link url="/icons/ico/fermer_red_long.gif"/>" value="<fl:getMessage code="A2002" alt="Annuler"/>" onclick="window.close();">
	</div>
</div>
</body>

</html>
<%
/******************************************************************************
 * CVS Log File - This is no longer maintained!
 *
 * Revision 1.2  2004/10/20 17:09:06  raphael
 * Correction des libellés
 *
 * Revision 1.1  2004/07/23 18:21:00  brian
 * Initial Revision
 *
 *****************************************************************************/
%>
