<%@page contentType="text/html;charset=UTF-8" autoFlush="true"%>
<%@page contentType="text/html;charset=UTF-8" autoFlush="true"%>
<%@page import="psdi.webclient.system.controller.*,psdi.webclient.system.beans.*, psdi.mbo.*, java.io.*,
 com.ibm.json.java.JSONArray,
 com.ibm.json.java.JSONObject,
 java.lang.Exception,
 psdi.webclient.system.session.*,
 psdi.server.MXServer,
 psdi.security.UserInfo,
 java.text.SimpleDateFormat,
 java.util.Date,
 java.util.Calendar,
 java.util.List,
 java.util.ArrayList,
 java.lang.* "%>
<%

String retour = "";
try {
    // get main record id
	int talPlanifId = Integer.parseInt(request.getParameter("talPlanifId"));
	
	// get mboSet for main object
	MXServer mxServer = MXServer.getMXServer();
	UserInfo userInfo = mxServer.getSystemUserInfo();

	MboSetRemote	talPlanifSet = mxServer.getMboSet("TAL_PLANIF",userInfo);
	talPlanifSet.setWhere("TAL_PLANIFID="+talPlanifId);
	MboRemote		talPlanif	= talPlanifSet.getMbo(0);

    JSONObject jsonBusinessHours = new JSONObject();
    if(talPlanif!=null){
        JSONObject jsonFIN = new JSONObject();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");        
        JSONArray daysOfWeek=new JSONArray();
        if(talPlanif.getInt("MONDAY")==1)
            daysOfWeek.add(1);
        if(talPlanif.getInt("TUESDAY")==1)
            daysOfWeek.add(2);
        if(talPlanif.getInt("WEDNESDAY")==1)
            daysOfWeek.add(3);
        if(talPlanif.getInt("THURSDAY")==1)
            daysOfWeek.add(4);
        if(talPlanif.getInt("FRIDAY")==1)
            daysOfWeek.add(5);
        if(talPlanif.getInt("SATURDAY")==1)
            daysOfWeek.add(6);
        if(talPlanif.getInt("SUNDAY")==1)
            daysOfWeek.add(0);

        jsonBusinessHours.put("startTime", sdf.format(talPlanif.getDate("STARTTIME").getTime()));
        jsonBusinessHours.put("endTime", sdf.format(talPlanif.getDate("ENDTIME").getTime()));
        jsonBusinessHours.put("daysOFWeek", daysOfWeek);
    }
    retour =   jsonBusinessHours.toString();
} catch (Exception e) {
out.println("Erreur serveur: " + e.getMessage());
e.printStackTrace();
}
%><%=retour%>