View Javadoc

1   /*Copyright (C) 2004-... Stephane Gauchet for Hyphonem
2   
3    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
4   
5    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6   
7    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8    
9    Written by St�phane Gauchet
10   mail me at : sgauchet@free.fr
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   * @author Stephane Gauchet pour Hyphonem
35   */
36  public class ModifEvtAction extends Action {
37  
38  	/**
39  	 * Constructor for CreateEvtAction.
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  			// on met la date du jour
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 }