1
2
3
4
5
6
7
8
9
10
11
12 package fr.hyphonem.conges.actions;
13
14 import java.text.ParseException;
15 import java.text.SimpleDateFormat;
16 import java.util.Calendar;
17 import java.util.Date;
18 import java.util.Vector;
19
20 import javax.servlet.ServletException;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23 import javax.servlet.http.HttpSession;
24
25 import org.apache.struts.action.Action;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29
30 import fr.hyphonem.conges.data.CalendarData;
31 import fr.hyphonem.conges.forms.AbsForm;
32
33
34
35
36 public class ModifEvtAction extends Action {
37
38
39
40
41 public ModifEvtAction() {
42 super();
43 }
44
45 public ActionForward execute(ActionMapping mapping, ActionForm form,
46 HttpServletRequest request, HttpServletResponse response)
47 throws java.io.IOException, ServletException {
48 HttpSession session = request.getSession();
49 if (session.getAttribute("user") == null) {
50 return mapping.findForward("invalidsession");
51 }
52
53 String date = request.getParameter("date");
54 if (date == null) {
55
56 Calendar today = Calendar.getInstance();
57 int day = today.get(Calendar.DAY_OF_MONTH);
58 int month = today.get(Calendar.MONTH) + 1;
59 int year = today.get(Calendar.YEAR);
60 date = day + "/" + month + "/" + year;
61 }
62 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
63 Date dateDeb;
64 try {
65 dateDeb = sdf.parse(date);
66 AbsForm absenceForm = new AbsForm();
67
68 Vector lstCal = (Vector) session.getAttribute("lstCalendarData");
69 for (int i = 0; i < lstCal.size(); i++) {
70 CalendarData cal = (CalendarData) lstCal.get(i);
71 Date dd = sdf.parse(cal.getDatedeb());
72 boolean theRightEvent = false;
73 if (dd.compareTo(dateDeb) == 0) {
74 if (request.getParameter("type") != null) {
75 String type = request.getParameter("type");
76 if (type.equals("matin") && cal.isCbmatin()) {
77 theRightEvent = true;
78 } else if (type.equals("aprem") && cal.isCbaprem()) {
79 theRightEvent = true;
80 } else {
81 theRightEvent = false;
82 }
83 } else {
84 theRightEvent = true;
85 }
86 } else {
87 theRightEvent = false;
88 }
89
90 if (theRightEvent) {
91 absenceForm.setId(cal.getId());
92 absenceForm.setDatedeb(cal.getDatedeb());
93 absenceForm.setDatefin(cal.getDatefin());
94 absenceForm.setCbmatin(cal.isCbmatin());
95 absenceForm.setCbaprem(cal.isCbaprem());
96 absenceForm.setRaison(cal.getRaison());
97 }
98 }
99 request.setAttribute("absForm", absenceForm);
100 } catch (ParseException e) {
101 dateDeb = null;
102 }
103
104 return mapping.findForward("success");
105 }
106 }