} else {
try {
oDtStart = oFmt.parse(sDtStart);
oDtEnd = oFmt.parse(sDtEnd);
oCon = oDbb.getConnection("HttpCalendarServlet.isavailableroom",true);
Room oRoom = new Room();
boolean bIsAvail;
if (oRoom.load(oCon, sRoom, sWrkA))
bIsAvail = oRoom.isAvailable(oCon, oDtStart, oDtEnd);
else
bIsAvail = false;
oCon.close("HttpCalendarServlet.isavailableroom");
oBuf.append("<calendarresponse command=\"isAvailableRoom\" code=\"0\"><error></error><value>"+String.valueOf(bIsAvail)+"</value></calendarresponse>");
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(oBuf.toString());
} catch (ParseException dpe) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid date it must be yyyyMMddHHmmss");
return;
} catch (SQLException sqle) {
try { if (oCon!=null) if (!oCon.isClosed()) oCon.close("HttpCalendarServlet.isavailableroom"); } catch (Exception ignore) { }
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sqle.getMessage());
return;
}
}
} else if (sCmd.equalsIgnoreCase("getRooms")) {
try {
DBSubset oRooms;
int nRooms;
oCon = oDbb.getConnection("HttpCalendarServlet.getrooms",true);
if (request.getParameter("type")==null) {
oRooms = new DBSubset(DB.k_rooms,DB.tp_room+","+DB.nm_room+","+DB.tx_comments, DB.gu_workarea+"=?", 100);
nRooms = oRooms.load(oCon, new Object[]{sWrkA});
} else if (request.getParameter("type").length()==0) {
oRooms = new DBSubset(DB.k_rooms,DB.tp_room+","+DB.nm_room+","+DB.tx_comments, DB.gu_workarea+"=?", 100);
nRooms = oRooms.load(oCon, new Object[]{sWrkA});
} else {
oRooms = new DBSubset(DB.k_rooms,DB.tp_room+","+DB.nm_room+","+DB.tx_comments, DB.gu_workarea+"=? AND "+DB.tp_room+"=?", 100);
nRooms = oRooms.load(oCon, new Object[]{sWrkA, request.getParameter("type")});
}
oBuf.append("<calendarresponse command=\"getRooms\" code=\"0\"><error></error><value>"+String.valueOf(nRooms)+"</value><rooms count=\""+String.valueOf(nRooms)+"\">");
for (int r=0; r<nRooms; r++) {
oBuf.append("<room type=\""+oRooms.getStringNull(0,r,"")+"\" active=\"1\"><name>"+oRooms.getStringNull(1,r,"")+"</name><comments>"+oRooms.getStringNull(2,r,"")+"</comments></room>");
} // next
oCon.close("HttpCalendarServlet.getavailablerooms");
oBuf.append("</rooms></calendarresponse>");
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(oBuf.toString());
} catch (SQLException sqle) {
try { if (oCon!=null) if (!oCon.isClosed()) oCon.close("HttpCalendarServlet.getrooms"); } catch (Exception ignore) { }
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sqle.getMessage());
return;
}
} else if (sCmd.equalsIgnoreCase("getAvailableRooms")) {
if (null==sDtStart) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter startdate is required");
} else if (null==sDtEnd) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter enddate is required");
} else {
try {
oDtStart = oFmt.parse(sDtStart);
oDtEnd = oFmt.parse(sDtEnd);
DBSubset oRooms = new DBSubset(DB.k_rooms,DB.tp_room+","+DB.nm_room+","+DB.tx_comments, DB.bo_available+"<>0 AND "+DB.gu_workarea+"=?", 100);
oCon = oDbb.getConnection("HttpCalendarServlet.getavailablerooms",true);
int nRooms = oRooms.load(oCon, new Object[]{sWrkA});
oBuf.append("<calendarresponse command=\"getAvailableRooms\" code=\"0\"><error></error><value>"+String.valueOf(nRooms)+"</value><rooms count=\""+String.valueOf(nRooms)+"\">");
Room oRomn = new Room();
for (int r=0; r<nRooms; r++) {
if (oRomn.load(oCon, oRooms.get(1,r), sWrkA)) {
if (oRomn.isAvailable(oCon, oDtStart, oDtEnd))
oBuf.append("<room type=\""+oRooms.getStringNull(0,r,"")+"\" active=\"1\"><name>"+oRooms.getStringNull(1,r,"")+"</name><comments>"+oRooms.getStringNull(2,r,"")+"</comments></room>");
}
} // next
oCon.close("HttpCalendarServlet.getavailablerooms");
oBuf.append("</rooms></calendarresponse>");
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(oBuf.toString());
} catch (ParseException dpe) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid date it must be yyyyMMddHHmmss");
return;
} catch (SQLException sqle) {
try { if (oCon!=null) if (!oCon.isClosed()) oCon.close("HttpCalendarServlet.getavailablerooms"); } catch (Exception ignore) { }
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sqle.getMessage());
return;
}
}
} else if (sCmd.equalsIgnoreCase("getMeetings") || sCmd.equalsIgnoreCase("getMeetingsOrganizedBy")) {
if (DebugFile.trace) DebugFile.writeln("Executing command "+sCmd);
if (null==sDtStart) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter startdate is requiered");
} else if (null==sDtEnd) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter enddate is requiered");
} else {
if (DebugFile.trace) DebugFile.writeln("startdate and enddate parameters acknowledged");
try {
if (DebugFile.trace) DebugFile.writeln("parsing startdate");
oDtStart = oFmt.parse(sDtStart);
if (DebugFile.trace) DebugFile.writeln("parsing enddate");
oDtEnd = oFmt.parse(sDtEnd);
DBSubset oMeets;
int nMeets;
if (sCmd.equalsIgnoreCase("getMeetings")) {
oMeets = new DBSubset(DB.k_meetings + " m," + DB.k_x_meeting_fellow + " f," + DB.k_fellows + " o",
"m." + DB.id_icalendar + ",m." + DB.gu_meeting + ",m." + DB.dt_start + ",m." + DB.dt_end + ",m." + DB.bo_private + ",m." + DB.tx_meeting + ",m." + DB.de_meeting +","+
"o." + DB.gu_fellow + ",o." + DB.id_ref + ",o." + DB.tx_name + ",o." + DB.tx_surname + ",o." + DB.tx_email + ",o." + DB.tx_timezone + ",m." + DB.tp_meeting,
"m."+DB.gu_workarea+"=? AND f."+DB.gu_fellow+"=o."+DB.gu_fellow+" AND "+
"f." + DB.gu_meeting + "=m." + DB.gu_meeting + " AND f." + DB.gu_fellow + "=? AND m." + DB.dt_start + " BETWEEN ? AND ? "+
(sType!=null ? " AND m."+DB.tp_meeting+"=?" : "")+" ORDER BY 3", 60);
} else {
oMeets = new DBSubset(DB.k_meetings + " m," + DB.k_fellows + " o",
"m." + DB.id_icalendar + ",m." + DB.gu_meeting + ",m." + DB.dt_start + ",m." + DB.dt_end + ",m." + DB.bo_private + ",m." + DB.tx_meeting + ",m." + DB.de_meeting +","+
"o." + DB.gu_fellow + ",o." + DB.id_ref + ",o." + DB.tx_name + ",o." + DB.tx_surname + ",o." + DB.tx_email + ",o." + DB.tx_timezone,
"m."+DB.gu_workarea+"=? AND m."+DB.gu_fellow+"=o."+DB.gu_fellow+" AND "+
"m." + DB.gu_fellow + "=? AND m." + DB.dt_start + " BETWEEN ? AND ? "+
(sType!=null ? " AND m."+DB.tp_meeting+"=?" : "")+" ORDER BY 3", 60);
}
oCon = oDbb.getConnection("HttpCalendarServlet.getmeetings",true);
if (sType==null)
nMeets = oMeets.load(oCon, new Object[]{sWrkA, sUid, new Timestamp(oDtStart.getTime()), new Timestamp(oDtEnd.getTime())});
else
nMeets = oMeets.load(oCon, new Object[]{sWrkA, sUid, new Timestamp(oDtStart.getTime()), new Timestamp(oDtEnd.getTime()), sType});
if (DebugFile.trace) DebugFile.writeln(String.valueOf(nMeets)+" meetings found");
oBuf.append("<calendarresponse command=\"getMeetings\" code=\"0\"><error></error><value>"+String.valueOf(nMeets)+"</value><meetings count=\""+String.valueOf(nMeets)+"\">");
for (int m=0; m<nMeets; m++) {
oBuf.append("<meeting type=\""+oMeets.getStringNull(13,m,"")+"\">");
oBuf.append("<id>"+oMeets.getStringNull(DB.id_icalendar,m,"")+"</id>");
oBuf.append("<gu>"+oMeets.getString(DB.gu_meeting,m)+"</gu>");
oBuf.append("<startdate>"+oMeets.getDateFormated(2,m,oXmt).replace(' ','T')+"</startdate>");
oBuf.append("<enddate>"+oMeets.getDateFormated(3,m,oXmt).replace(' ','T')+"</enddate>");
if (oMeets.isNull(4,m))
oBuf.append("<privacy>false</privacy>");
else
oBuf.append("<privacy>"+String.valueOf(oMeets.getShort(4,m)!=0)+"</privacy>");
oBuf.append("<title>"+oMeets.getStringNull(5,m,"")+"</title>");
oBuf.append("<description>"+oMeets.getStringNull(6,m,"")+"</description>");
oBuf.append("<organizer>");
oBuf.append("<id>"+oMeets.getStringNull(8,m,"")+"</id>");
oBuf.append("<gu>"+oMeets.getString(7,m)+"</gu>");
oBuf.append("<name>"+oMeets.getStringNull(9,m,"")+"</name>");
oBuf.append("<surname>"+oMeets.getStringNull(10,m,"")+"</surname>");
oBuf.append("<email>"+oMeets.getStringNull(11,m,"")+"</email>");
oBuf.append("<timezone>"+oMeets.getStringNull(12,m,"")+"</timezone>");
oBuf.append("</organizer>");
DBSubset oRomm = new DBSubset(DB.k_rooms+" r,"+DB.k_x_meeting_room+" m","r."+DB.tp_room+",r."+DB.nm_room+",r."+DB.tx_comments+",r."+DB.bo_available,
"r."+DB.gu_workarea+"=? AND m."+DB.gu_meeting+"=? AND r."+DB.nm_room+"=m."+DB.nm_room, 10);
int nRomm = oRomm.load(oCon, new Object[]{sWrkA, oMeets.getString(DB.gu_meeting,m)});
oBuf.append("<rooms count=\""+String.valueOf(nRomm)+"\">");
for (int r=0; r<nRomm; r++) {
oBuf.append("<room type=\""+oRomm.getStringNull(0,r,"")+"\" ");
if (oRomm.isNull(3,r))
oBuf.append("active=\"1\"");
else
oBuf.append("active=\""+String.valueOf(oRomm.getShort(3,r))+"\"");
oBuf.append("><name>"+oRomm.getStringNull(1,r,"")+"</name><comments>"+oRomm.getStringNull(2,r,"")+"</comments></room>");
} // next
oBuf.append("</rooms>");
DBSubset oFlws = new DBSubset(DB.k_fellows +" f,"+DB.k_x_meeting_fellow +" x",
"f." + DB.gu_fellow + ",f." + DB.id_ref + ",f." + DB.tx_name + ",f." + DB.tx_surname + ",f." + DB.tx_email + ",f." + DB.tx_timezone,
"f."+DB.tx_email+" IS NOT NULL AND f."+DB.gu_fellow+"=x."+DB.gu_fellow+" AND x."+DB.gu_meeting+"=?", 10);
DBSubset oCnts = new DBSubset(DB.k_member_address+" c,"+DB.k_x_meeting_contact+" x",
"c." + DB.gu_contact + ",c." + DB.id_ref + ",c." + DB.tx_name + ",c." + DB.tx_surname + ",c." + DB.tx_email + ",'+00:00' AS " + DB.tx_timezone,
"c."+DB.tx_email+" IS NOT NULL AND c."+DB.gu_contact+"=x."+DB.gu_contact+" AND x."+DB.gu_meeting+"=?", 10);
oFlws.load(oCon, new Object[]{oMeets.getString(DB.gu_meeting,m)});
oCnts.load(oCon, new Object[]{oMeets.getString(DB.gu_meeting,m)});
oFlws.union(oCnts);
oBuf.append("<attendants count=\""+String.valueOf(oFlws.getRowCount())+"\">");
for (int f=0; f<oFlws.getRowCount(); f++) {
oBuf.append("<attendant>");
oBuf.append("<id>"+oFlws.getStringNull(1,f,"")+"</id>");
oBuf.append("<gu>"+oFlws.getString(0,f)+"</gu>");
oBuf.append("<name>"+oFlws.getStringNull(2,f,"")+"</name>");
oBuf.append("<surname>"+oFlws.getStringNull(3,f,"")+"</surname>");
oBuf.append("<email>"+oFlws.getStringNull(4,f,"")+"</email>");
oBuf.append("<timezone>"+oFlws.getStringNull(5,f,"")+"</timezone>");
oBuf.append("</attendant>");
}
oBuf.append("</attendants>");
oBuf.append("</meeting>");
} // next
oCon.close("HttpCalendarServlet.getmeetings");
oBuf.append("</meetings></calendarresponse>");
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(oBuf.toString());
} catch (ParseException dpe) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid date it must be yyyyMMddHHmmss");
return;
} catch (SQLException sqle) {
try { if (oCon!=null) if (!oCon.isClosed()) oCon.close("HttpCalendarServlet.getmeetings"); } catch (Exception ignore) { }
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sqle.getMessage());
return;
}
}
} else if (sCmd.equalsIgnoreCase("getMeetingsForRoom")) {
if (null==sRoom) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter room is requiered");
} else if (null==sDtStart) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter startdate is requiered");
} else if (null==sDtEnd) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter enddate is requiered");
} else {
try {
oDtStart = oFmt.parse(sDtStart);
oDtEnd = oFmt.parse(sDtEnd);
DBSubset oMeets = new DBSubset(DB.k_meetings + " m," + DB.k_x_meeting_fellow + " f," +DB.k_x_meeting_room + " r," + DB.k_fellows + " o",
"m." + DB.id_icalendar + ",m." + DB.gu_meeting + ",m." + DB.dt_start + ",m." + DB.dt_end + ",m." + DB.bo_private + ",m." + DB.tx_meeting + ",m." + DB.de_meeting+","+
"o." + DB.gu_fellow + ",o." + DB.id_ref + ",o." + DB.tx_name + ",o." + DB.tx_surname + ",o." + DB.tx_email + ",o." + DB.tx_timezone + ",m." + DB.tp_meeting,
"m."+DB.gu_workarea+"=? AND r."+DB.nm_room+"=? AND "+
"r." + DB.gu_meeting + "=m." + DB.gu_meeting + " AND f."+DB.gu_fellow+"=o."+DB.gu_fellow+" AND "+
"f." + DB.gu_meeting + "=m." + DB.gu_meeting + " AND " +
"f." + DB.gu_fellow + "=? AND m." + DB.dt_start + " BETWEEN ? AND ? ORDER BY 3", 60);
oCon = oDbb.getConnection("HttpCalendarServlet.getmeetingsforroom",true);
int nMeets = oMeets.load(oCon, new Object[]{sWrkA, sRoom, sUid, new Timestamp(oDtStart.getTime()), new Timestamp(oDtEnd.getTime())});
oBuf.append("<calendarresponse command=\"getMeetings\" code=\"0\"><error></error><value>"+String.valueOf(nMeets)+"</value><meetings count=\""+String.valueOf(nMeets)+"\">");
for (int m=0; m<nMeets; m++) {
oBuf.append("<meeting type=\""+oMeets.getStringNull(13,m,"")+"\">");
oBuf.append("<id>"+oMeets.getStringNull(DB.id_icalendar,m,"")+"</id>");
oBuf.append("<gu>"+oMeets.getString(DB.gu_meeting,m)+"</gu>");
oBuf.append("<startdate>"+oMeets.getDateFormated(2,m,oXmt).replace(' ','T')+"</startdate>");
oBuf.append("<enddate>"+oMeets.getDateFormated(3,m,oXmt).replace(' ','T')+"</enddate>");
if (oMeets.isNull(4,m))
oBuf.append("<privacy>false</privacy>");
else
oBuf.append("<privacy>"+String.valueOf(oMeets.getShort(4,m)!=0)+"</privacy>");
oBuf.append("<title>"+oMeets.getStringNull(5,m,"")+"</title>");
oBuf.append("<description>"+oMeets.getStringNull(6,m,"")+"</description>");
oBuf.append("<organizer>");
oBuf.append("<id>"+oMeets.getStringNull(8,m,"")+"</id>");
oBuf.append("<gu>"+oMeets.getString(7,m)+"</gu>");
oBuf.append("<name>"+oMeets.getStringNull(9,m,"")+"</name>");
oBuf.append("<surname>"+oMeets.getStringNull(10,m,"")+"</surname>");
oBuf.append("<email>"+oMeets.getStringNull(11,m,"")+"</email>");
oBuf.append("<timezone>"+oMeets.getStringNull(12,m,"")+"</timezone>");
oBuf.append("</organizer>");
Room oRoom = new Room();
oRoom.load(oCon, sRoom, sWrkA);
oBuf.append("<rooms count=\"1\">");
oBuf.append("<room type=\""+oRoom.getStringNull(DB.tp_room,"")+"\" active=\""+(oRoom.get(DB.bo_available)==null ? "1" : oRoom.get(DB.bo_available))+"\"><name>"+oRoom.getStringNull(DB.nm_room,"")+"</name><comments>"+oRoom.getStringNull(DB.tx_comments,"")+"</comments></room>");
oBuf.append("</rooms>");
DBSubset oFlws = new DBSubset(DB.k_fellows +" f,"+DB.k_x_meeting_fellow +" x",
"f." + DB.gu_fellow + "f." + DB.id_ref + ",f." + DB.tx_name + "f." + DB.tx_surname + "f." + DB.tx_email + "f." + DB.tx_timezone,
"f."+DB.tx_email+" IS NOT NULL AND f."+DB.gu_fellow+"=x."+DB.gu_fellow+" AND x."+DB.gu_meeting+"=?", 10);
DBSubset oCnts = new DBSubset(DB.k_member_address+" c,"+DB.k_x_meeting_contact+" x", "c."+DB.tx_email, "c."+DB.tx_email+" IS NOT NULL AND c."+DB.gu_contact+"=x."+DB.gu_contact+" AND x."+DB.gu_meeting+"=?", 10);